Title: query_posts and sticky posts
Last modified: August 20, 2016

---

# query_posts and sticky posts

 *  Resolved [teatall](https://wordpress.org/support/users/teatall/)
 * (@teatall)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query_posts-and-sticky-posts/)
 * Hi guys!
 * Hate to bother but I really need some help.
 * I used query_posts to pull sticky posts under a certain category. Here’s what
   I want, but it seems to be beyond me.
 * Let’s say there are 10 sticky posts and 20 normal posts under this category.
   
   Is it possible to have the 5 latest sticky posts at the top of the list while
   the other 5 will be listed together with the 20 normal posts in the order of 
   time?
 * Any help will be appreciated!

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query_posts-and-sticky-posts/#post-3337118)
 * You must use two loops to do this. In the first loop, set posts_per_page to 5
   and ignore_sticky_posts to 0. In that loop, add all IDs found to a ‘$do_not_duplicate’
   array’.
 * In the second loop, set ignore_sticky_posts to 1, and post__not_in to the $do_not_duplicate
   array.
 *  Thread Starter [teatall](https://wordpress.org/support/users/teatall/)
 * (@teatall)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query_posts-and-sticky-posts/#post-3337123)
 * thanks buddy!
    that’s quite illuminating.
 *  Thread Starter [teatall](https://wordpress.org/support/users/teatall/)
 * (@teatall)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query_posts-and-sticky-posts/#post-3337125)
 * I tried your method a couple of times, but still failed. could you plz help me
   look at the following code and tell me where should i put the ‘$do_not_duplicate’
   array?
 * i now would like to have three latest sticky posts at the top of the list.
 *     ```
       $sticky=array(
                               'cat'=>2,/*category to be displayed*/
                               'showposts'=>3,/*number of posts to be displayed*/
                               'post__in'=>get_option('sticky_posts'));
       $others=array(
                               'cat'=>2,/*category to be displayed*/
                               'showposts'=>7,/*number of posts to be displayed*/);
       /*the query*/
       query_posts( $sticky );
       /*the 1st loop*/
       while ( have_posts() ) : the_post();
           echo '<li><a href="';
           the_permalink();
           echo '" title="';
           the_title();
           echo '">';
           get_short_title();
           echo '</a><span>';
           the_time('Y-m-d');
           echo '</span>';
       endwhile;
       /*reset query*/
       wp_reset_query();
       /*the 2nd query*/
       query_posts( $others );
       /*the loop*/
       while ( have_posts() ) : the_post();
           echo '<li><a href="';
           the_permalink();
           echo '" title="';
           the_title();
           echo '">';
           get_short_title();
           echo '</a><span>';
           the_time('Y-m-d');
           echo '</span>';
       endwhile;
       /*reset query*/
       wp_reset_query();
       ```
   
 * thanks again!
 *  Thread Starter [teatall](https://wordpress.org/support/users/teatall/)
 * (@teatall)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query_posts-and-sticky-posts/#post-3337138)
 * I have already solved the problem. thanks a lot!

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

The topic ‘query_posts and sticky posts’ is closed to new replies.

## Tags

 * [post](https://wordpress.org/support/topic-tag/post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [teatall](https://wordpress.org/support/users/teatall/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/query_posts-and-sticky-posts/#post-3337138)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
