[wp-hackers] Sticky posts turning up in my custom WP Queries
Nathan Rice
ncrice at gmail.com
Wed May 13 18:24:16 GMT 2009
Excluding stickies from a query is pretty easy ...
http://www.nathanrice.net/blog/definitive-sticky-posts-guide-for-wordpress-27/
(scroll down to the "a custom loop to ignore stick posts" section)
Nathan
My Website
http://www.nathanrice.net/
My Twitter
http://twitter.com/nathanrice
On Wed, May 13, 2009 at 2:08 PM, Simon Wheatley
<simon at sweetinteraction.com>wrote:
> 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
> example:
>
> $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.
>
> Thoughts?
>
> Thanks in advance.
>
> S
>
>
> ---
> Sweet Interaction Ltd is Registered in England/Wales, no. 6610741
> Registered office: 7 Malton Av, Manchester, M21 8AT
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list