[wp-hackers] Sticky posts turning up in my custom WP Queries

Simon Wheatley simon at sweetinteraction.com
Wed May 13 18:08:07 GMT 2009

Now maybe this is my comeuppance for using custom WP_Queries in recent
projects, but I've just hit an issue with sticky posts showing up on
loops outside the homepage. I create a custom WP_Query manually, for

$args = array(
	'post_type' => $post_type,
	'what_to_show' => 'posts',
	'post_status' => 'publish',
	'posts_per_page' => $num_posts,
	'orderby' => 'modified',
	'order' => 'DESC',
	's' => $search_string,

$my_query = new WP_Query( $args );

Unfortunate thing 1: it seems that this query gets interpreted as
is_home = true, this is because of this line in WP_Query:

if ( !( $this->is_singular || $this->is_archive || $this->is_search ||
$this->is_feed || $this->is_trackback || $this->is_404 ||
$this->is_admin || $this->is_comments_popup ) )

Unfortunate thing 2: the fact that the Query is now interpreted as
is_home means that the conditional IF around putting sticky posts in
now evaluates to true, this is that conditional:

if ( $this->is_home && $page <= 1 && !empty($sticky_posts) &&
!$q['caller_get_posts'] ) {

All these things seem perfectly logical in and of themselves, but in
combination they conspire to trip me up when I create custom
WP_Queries for my custom loops on various templates.

Initially I thought to call for a new filter on $sticky_posts in
WP_Query, around line 2303... but I now wonder if the conditional
evaluating whether is_home should be true is at fault and maybe this
needs something extra, or maybe a filter on is_home.


Thanks in advance.


Sweet Interaction Ltd is Registered in England/Wales, no. 6610741
Registered office: 7 Malton Av, Manchester, M21 8AT

More information about the wp-hackers mailing list