change this code to random post?
-
Hello everyone! I am using the code below to display the most recent post from a certain category on a specific page. How can I modify this to display a random post from multiple specific categories instead? Or is there some entirely different code I should use?
<?php // page id 224 will get category ID 7 posts if (is_page('224') ) { $cat = array(7); } else { $cat = ''; } $showposts = 1; // -1 shows all posts $do_not_show_stickies = 1; // 0 to show stickies $args=array( 'category__in' => $cat, 'showposts' => $showposts, 'caller_get_posts' => $do_not_show_stickies ); $my_query = new WP_Query($args); ?> <?php if( $my_query->have_posts() ) : ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php //necessary to show the tags global $wp_query; $wp_query->in_the_loop = true; ?>
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘change this code to random post?’ is closed to new replies.