Title: query_posts in sidebar
Last modified: August 19, 2016

---

# query_posts in sidebar

 *  [webguy262](https://wordpress.org/support/users/webguy262/)
 * (@webguy262)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query_posts-in-sidebar-1/)
 * Trying to get the sidebar to display certain posts based on page / parent id.
 * The ‘if’ part works, but the ‘else’ fails to display anything. I want the ‘else’
   to return the last three posts regardless of category.
 *     ```
       <?php
       global $post;
       if (125 == $post->post_parent || 125 == $post->ID || 705 == $post->post_parent || 705 == $post->ID) {
       query_posts( array( 'category__in' => array(5, 9, 155), 'posts_per_page' => 3 ) );
       } else {
       query_posts( 'posts_per_page=3' );
       }
       ?>
       ```
   
 * What am I missing?

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

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query_posts-in-sidebar-1/#post-2001431)
 * review this codex guide and see if it helps: [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  [Igor Yavych](https://wordpress.org/support/users/flyerua/)
 * (@flyerua)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query_posts-in-sidebar-1/#post-2001471)
 * sorry, posted wrong thing

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

The topic ‘query_posts in sidebar’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 3 participants
 * Last reply from: [Igor Yavych](https://wordpress.org/support/users/flyerua/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/query_posts-in-sidebar-1/#post-2001471)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
