Title: Query Posts-previous five posts how?
Last modified: August 18, 2016

---

# Query Posts-previous five posts how?

 *  [lokjah](https://wordpress.org/support/users/lokjah/)
 * (@lokjah)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/)
 * Hey there, I would like to use the admin panel setting to show a certain number
   of posts on my blog say 5, but then I would like to do a query posts after that
   initial loop and show a list of the previous 5 posts (post id and title permalink
   only). I want it to be category independent, meaning it doesnt matter what category
   the posts are in, just show the next 5 in chronological order.
 * *and as an alternate, is there a way to show the next 5 as a random list also?
 * the one I’ve got now shows 5 posts but it shows the same 5 posts as the initial
   loop (I have 5 set in wp admin to show)
 * `<ul id="previously">
    <?php query_posts('showposts=5'); ?> <?php while (have_posts()):
   the_post(); ?> <li><?php the_ID(); ?> <a href="<?php the_permalink() ?>" rel="
   bookmark" title="Permanent Link to <?php the_title(); ?>"></a></li> <?php endwhile;?
   > </ul>
 * thanks

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Firas](https://wordpress.org/support/users/firas/)
 * (@firas)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238213)
 * Just a tip: if you only want to show id and permalink, use the much easier [get_posts](http://codex.wordpress.org/Template_Tags/get_posts).
 *  Thread Starter [lokjah](https://wordpress.org/support/users/lokjah/)
 * (@lokjah)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238217)
 * ah cool, so would I do something like:
 *  `$posts = get_posts('numberposts=5&offset=5);
    foreach($posts as $post) : ?>
 * to show the previous 5 after the first loop of 5?
 *  Thread Starter [lokjah](https://wordpress.org/support/users/lokjah/)
 * (@lokjah)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238224)
 * sweet that worked dope! thanks firas….
 * now how about getting that previous 5 as random titles?
 *  [Firas](https://wordpress.org/support/users/firas/)
 * (@firas)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238236)
 * Try doing `shuffle($posts);` right before the foreach loop?
 *  Thread Starter [lokjah](https://wordpress.org/support/users/lokjah/)
 * (@lokjah)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238307)
 * hmmm close firas
 * that seems to shuffle the order of the outputted post list, what I really wanted
   was it to pull random posts from all my posts..
 * this shuffle is cool tho..
 * maybe there isnt enough parameters in the get_posts to do this and I might need
   to go back to a second loop?
 *  Thread Starter [lokjah](https://wordpress.org/support/users/lokjah/)
 * (@lokjah)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238311)
 * ah one more thing.. im getting the same post id for each of those titles, and
   its actually the same post id as the last one in the first loop..
 * eg, the last post in my blog (#5) is post id 88, the code I’m using below shows
   each of these next 5 as post id 88 also, the titles work fine but not the id..
 * `<ul id="previous">
    <?php $posts = get_posts('numberposts=5&offset=5'); //shuffle(
   $posts); shuffles order of output posts foreach($posts as $post) : ?> <li><?php
   the_ID(); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </
   li> <?php endforeach; ?> </ul>
 * in action_
 * [http://clintfisherart.com/news/](http://clintfisherart.com/news/)
 *  Thread Starter [lokjah](https://wordpress.org/support/users/lokjah/)
 * (@lokjah)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238319)
 * argh.. helps if I read…
 * `setup_postdata($post);`
 * thats sussed… 🙂
 * just need to know how to do the random one now so it grabs 5 from all my posts
   available, rather than the 5 in the offset…
 * any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Query Posts-previous five posts how?’ is closed to new replies.

## Tags

 * [five](https://wordpress.org/support/topic-tag/five/)
 * [previous](https://wordpress.org/support/topic-tag/previous/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [lokjah](https://wordpress.org/support/users/lokjah/)
 * Last activity: [20 years, 10 months ago](https://wordpress.org/support/topic/query-posts-previous-five-posts-how/#post-238319)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
