[wp-trac] [WordPress Trac] #21687: Need to be able to float sticky posts to top in custom queries

WordPress Trac wp-trac at lists.automattic.com
Sat Aug 25 16:12:08 UTC 2012


#21687: Need to be able to float sticky posts to top in custom queries
----------------------------+-----------------------------
 Reporter:  ChemicalSailor  |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Query           |    Version:  3.4
 Severity:  normal          |   Keywords:
----------------------------+-----------------------------
 Currently sticky posts are only floated to the top of the loop when on an
 index page (blog/home). When making a new WP_Query for posts as a
 secondary loop on a "page" page (whilst developing shortcode) sticky posts
 only appear in the natural date order because my query does not have the
 is_home flag.

 My proposal would be to add a new parameter/argument to the WP_Query
 class, either connected to 'orderby' or 'ignore_sticky' parameters,
 stating whether sticky posts should have order 'float', 'natural',
 'exclude' (it seems that the mechanism for excluding sticky posts from the
 loop is a bit clunky, although well documented; this would simplify it).
 Default behaviour can be retained, the query on the index page can use the
 'float' option and themes/plugins can call it in custom queries if
 required.

 Alternatively, the sticky sorting could be moved to a separate function
 and called via an action, so developers can use the same function (or
 build their own) in their custom queries. This is how I have my current
 workaround, running a filter on 'posts_results' having copied code for
 floating stickies from core. It seems a shame to be be duplicating code
 though, especially when it should be an option available in custom
 queries.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21687>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list