Display only 1 random post from the most recent 20
-
Hello, I am trying to display only 1 random post from the most recent 20 posts. Currently, this is the code I have. The issue is, only the latest post is displaying since showposts =>1.
$post_id = get_the_ID(); $args = array( 'orderby' => 'post_date', 'orderby' => 'rand', 'showposts'=>1, 'post__not_in' => array($post_id), 'meta_query' => array(array('key' => '_thumbnail_id')) ); $rand_query = new WP_Query($args); while ($rand_query->have_posts()) : $rand_query->the_post();
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Display only 1 random post from the most recent 20’ is closed to new replies.