Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#21687 closed enhancement (duplicate)

Need to be able to float sticky posts to top in custom queries

Reported by: chemicalsailor's profile ChemicalSailor Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Query Keywords:
Focuses: Cc:


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.

Change History (1)

#1 @wonderboymusic
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#11950 has a patch and basically give you control over when stickies are tacked on the front. Doesn't solve the is_home() problem, but let's move the discussion over there.

Note: See TracTickets for help on using tickets.