[wp-hackers] Using Sticky Posts in Custom Queries

Matt Slocum mattslocum at sharefaith.com
Tue Dec 20 18:17:29 UTC 2011

This is my first post, so hello to everyone.

I'm extremely confused with Sticky Posts. No matter what I try I can't get
them to behave the way I'm under the impression that they are supposed to.
All the searching and googling that I've done seems to only return how to
ignore sticky posts or fetch only sticky posts.

I've setup a custom query on the homepage that pulls anything from the
category_name 'HomePage'. I'm using a new WP_QUERY class to do my loop. I'm
under the impression that sticky posts are supposed to show up on top by
default, but they are getting sorted by date like the rest of the posts.
The query runs on the home page, so I can't figure out why they aren't
showing up on top. Do I need to tell the query to sort on sticky somehow?

---------- my query --------------
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
                'category_name' => 'HomePage',
                'paged' => $paged
    $home_query = new WP_QUERY();

The WordPress documentation gives examples on how to query only sticky and
how to query non-sticky. Am I supposed to do two queries? That doesn't
sound right. And it will be extra work to maintain the correct amount of
posts per page if I'm running 2 queries.

Any help is appreciated,

More information about the wp-hackers mailing list