[wp-testers] Something odd happening with WP_Query()

Paul Robinson pablorobinson at gmail.com
Sat Nov 29 21:53:58 GMT 2008


I can't test it at the moment but I believe it will work. I had a problem
with a plugin I used that checked to see if it was running in the loop. If I
disabled the check it worked. So I'm assuming that it would be the same.

2008/11/29 Gaarai <gaarai at gaarai.com>

> I figured that there might be something obscure like that. I work on the
> back-end mostly, so I'm not aware of all the quirks of the front-end.
>
> I traced all the function calls for calling the_tags(), and I believe that
> I found the problem. One of the functions in the call stack for the_tags()
> makes a call to in_the_loop(). The in_the_loop() function simply has the
> following code:
>
>   function in_the_loop() {
>       global $wp_query;
>
>       return $wp_query->in_the_loop;
>   }
>
> I haven't tested this, but I believe if you manually set that var to true
> before you start your custom loop and then set it back afterwards, you can
> work past that limitation.
>
> So unfortunately, it seems that you still have to do a hack job, but at
> least its not as problem laden as having to deal with PHP4/PHP5
> compatibility issues resulting from differences in how each handles object
> assignments.
>
> To clarify my idea, you could do the following:
>
>   global $wp_query;
>   $wp_query->in_the_loop = true;
>
>   /* custom loop code */
>
>   $wp_query->in_the_loop = false;
>
> I'm not saying that this is a good idea or that it will work, but it might
> help someone out there that doesn't want to deal with the mess. Having that
> code seems much more understandable to me than all the odd assignments to
> null, temp variables, etc.
>
> If you try it out, let me know if it works. If it doesn't, there might be
> another reference to the $wp_query variable that I missed.
>
> - Chris Jean
>
>
> Paul Robinson wrote:
>
>> That is what was causing the problem for me. If I created a custom
>> variable
>> it caused the problems of the_tags() not working. As soon as I changed it
>> to
>> use $wp_query it worked great. So to be honest I don't have a clue.
>>
>> 2008/11/29 Gaarai <gaarai at gaarai.com>
>>
>>
>>
>>> I'm curious why people are trying to use the $wp_query variable at all.
>>> Simply create your own variable with a unique name, such as $my_query,
>>> and
>>> avoid all these problems entirely.
>>>
>>> - Chris Jean
>>>
>>> -- snip --
>>>
>>> _______________________________________________
>>> wp-testers mailing list
>>> wp-testers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>>
>>>
>>>
>> _______________________________________________
>> wp-testers mailing list
>> wp-testers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>
>>
>>
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>


More information about the wp-testers mailing list