[wp-hackers] wp_query gets poisoned by new WP_Query objects

Otto otto at ottodestruct.com
Thu Oct 8 13:44:36 UTC 2009


Well, I'm honestly not sure why you're cloning and then overwriting
$wp_query to begin with, but yes, in this context, you should be using
query_posts.

When you want to override the "main" query, you use query_posts.

When you want to create a new, separate query, you use a new WP_Query
object (assigned to some local variable).

In no real case that I can think of would you want to create a new
WP_Query and assign it to the global $wp_query variable.

-Otto



On Thu, Oct 8, 2009 at 8:14 AM, Luke Gallagher <notfornoone at gmail.com> wrote:
> While working with Wordpress I found some odd behaviour, and before I
> continue to get this patched I am wondering if anyone can verify that this
> is actually bug or if it is the intended behaviour of Wordpress.
>
> Here is a previous bug that may be related:
> http://core.trac.wordpress.org/ticket/9854
>
> I have verified that the following is the case for the current checkout of
> the Wordpress core.
>
> If I create a custom wp_query object in the default theme's page.php file,
> right after get_header() like so:
> http://gist.github.com/204994
>
> and I have a posts_join filter in /wp-content/themes/default/functions.php
> that prints out to the error_log what type of request this is. ( I also
> tried this out with posts_where and pre_get_posts with the same results )
>
> Loading the about page in the web browser I get the following in error log:
>
> is_page
> is_singular
> -------
> is_page
> is_singular
> -------
>
>
> But if I do it this way I get:
> http://gist.github.com/204996
>
> is_page
> is_singular
> -------
> is_archive
> is_category
> -------
>
>
> I would think that the latter result is the correct behaviour, should be so
> in the first instance.
>
> Using query_posts instead in the same situation works:
> http://gist.github.com/205004
>
> is_page
> is_singular
> -------
> is_archive
> is_category
> -------
>
> So should I just be using query_posts in this context?
> Is there something that I'm missing here?
>
> thanks,
>
> Luke
>
>
>
> _______________________________________________
> 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