Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

f1ss1on on "Display only 1 random post from the most recent 20"

$
0
0

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 all articles
Browse latest Browse all 8245

Trending Articles