[wp-hackers] Loops and Cloning

Otto otto at ottodestruct.com
Sun Nov 2 16:09:42 GMT 2008


On Sun, Nov 2, 2008 at 3:27 AM, Malaiac <malaiac at gmail.com> wrote:
> 2008/11/1 Jess Planck <jess at funroe.net>:
>> On Oct 31, 2008, at 9:27 PM, Mark Jaquith wrote:
>>
>>> It's better to just instantiate your own WP_Query object.
>
> Trouble with instantiating another WP_Query is that filters and
> actions have NO way to know on which wp_query object they are working
> on.
> What if I need some filtering on one custom wp_query object, but none
> on the main wp_query loop ?
> The filter has to work depending on current query_vars... but how
> could it know them ? (global $wp_query;
> print_r($wp_query->query_vars); will work on the main wp_query, but
> not on the custom one)
>
> Possible solutions :
> adding an optional query_var "name"  to each wp_query object

The query_vars *ARE* part of the WP_Query object. The global $wp_query
itself is a WP_Query object, it's just the default one.

$q = new WP_Query('queryvars=whatever');
print_r($q->query_vars);


More information about the wp-hackers mailing list