Title: Retrieve adjacent posts query
Last modified: August 20, 2016

---

# Retrieve adjacent posts query

 *  [lostmodern3d](https://wordpress.org/support/users/lostmodern3d/)
 * (@lostmodern3d)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/retrieve-adjacent-posts-query/)
 * Hi
 * My theme (Imbalance) retrieves 2 featured posts in the sidebar with :
 * query_posts(“showposts=2&offset=1”);
 * but it always calls the 2 same featured posts.
 * Is there a way to adjust the query to retrieve the adjacent (previous and next)
   posts in the same category?

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

 *  Thread Starter [lostmodern3d](https://wordpress.org/support/users/lostmodern3d/)
 * (@lostmodern3d)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/retrieve-adjacent-posts-query/#post-2310411)
 * the full php string might be useful
 * <?php
    wp_reset_query(); query_posts(“showposts=2&offset=1”); if ( have_posts()):
   while ( have_posts() ) : the_post(); ?>
 * thanks
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/retrieve-adjacent-posts-query/#post-2310420)
 * > Is there a way to adjust the query to retrieve the adjacent (previous and next)
   > posts in the same category?
 * Nope – but you could randomize the post order.
 *     ```
       <?php
       wp_reset_query();
       query_posts("posts_per_page=2&offset=1&orderby=rand");
       if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       ```
   
 *  Thread Starter [lostmodern3d](https://wordpress.org/support/users/lostmodern3d/)
 * (@lostmodern3d)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/retrieve-adjacent-posts-query/#post-2310499)
 * Thanks esmi for the fast suggestion.
    There must be a way to call the adjacent
   post, plugins like [post navigation](http://dennishoppe.de/wordpress-plugins/post-navigation-widget)
   do it. query_posts() is maybe not the best solution, what about wp_query() or
   get_adjacent_post()? But randomizing is a really cool idea, even maybe better.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/retrieve-adjacent-posts-query/#post-2310522)
 * In theory, it is possible to grab the previous and next posts but I think it 
   would mean running 2 extra queries just for that – which you might want to have
   a think about first.

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

The topic ‘Retrieve adjacent posts query’ is closed to new replies.

## Tags

 * [imbalance](https://wordpress.org/support/topic-tag/imbalance/)
 * [navigation](https://wordpress.org/support/topic-tag/navigation/)
 * [next](https://wordpress.org/support/topic-tag/next/)
 * [previous](https://wordpress.org/support/topic-tag/previous/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/retrieve-adjacent-posts-query/#post-2310522)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
