• Hello
    I have a category with 10 posts.
    I want to make a query_posts posts that displays only one, but random and only the five most recent posts.
    I know mount query_posts to:
    View posts only 1,
    View randomly,
    BUT I do not know among the 10 existing posts, working only with the five most recent posts.
    Any tips?
    Thank you.

Viewing 1 replies (of 1 total)
  • I think this will do what you want:

    $args = array(
       'cat' => 55,          // Your category id here
       'posts_per_page' => 5,
       'orderby' => 'rand',
       'ignore_sticky_posts' => 1
    );
    query_posts($args);
    if (have_posts()) : while (have_posts()) : the_post();
          // Your code to display the post here
          break;  // Exit loop after first post
       endwhile;
    endif;
Viewing 1 replies (of 1 total)
  • The topic ‘query_posts: Display a random post from the most recent 5 out of 10 posts?’ is closed to new replies.