[wp-testers] Conditional tags not working

Nathan Rice ncrice at gmail.com
Sun Jan 17 20:15:33 UTC 2010


My apologies ... I thought I remembered this working at some point before,
but it looks like I was wrong.

is_admin() does indeed work when used in functions.php.

So, as a followup question ... what hooks are best to use if I want to be
able to use the conditionals? Someone already mentioned template_redirect
... are there any others? Is there a good resource that defines what hooks
are fired before and after WP knows what type of query it is?

Thanks!

------------------
Nathan Rice
WordPress and Web Development
www.nathanrice.net | twitter.com/nathanrice


On Sun, Jan 17, 2010 at 6:02 AM, Peter Westwood
<peter.westwood at ftwr.co.uk>wrote:

>
> On 17 Jan 2010, at 05:21, Nathan Rice wrote:
>
>  As this post points out:
>>
>> http://weblogtoolscollection.com/archives/2010/01/16/fix-for-is_home-is_archive-not-working/
>>
>> conditional tags like is_home(), is_page, is_archive(), etc., are all
>> seemingly not working. I've noticed this as well (running 2.9.1).
>>
>> I believe that it might work in some circumstances (like in the loop?),
>> but
>> I am currently running into the problem when trying to conditionally do
>> something in the theme's functions.php file.
>>
>> The article linked to above suggests using wp_reset_query() before using a
>> conditional, but that does NOT work in functions.php, though it may work
>> in
>> a file like footer.php.
>>
>> Does anyone have any clue as to why this is happening? I dumped the
>> $wp_query object and all the conditionals in them have null values, which
>> is
>> of course why conditional tags aren't working ... which begs the question,
>> why isn't the $wp_query object returning accurate values for the
>> conditionals?
>>
>> I'm stumped. Any takers?
>>
>
> I have replied on the post as the example there looks very much like a call
> to query_posts has been made to run a second query.
>
> As said by others, you cannot use any of the query related conditionals
> until the query has been run.
>
> This means that you have to use a hook like template_redirect from a plugin
> or functions.php to do conditional specific things.
>
> Basically any hook which runs after WP::query_posts().
>
> Cheers
>
> Peter
> --
> Peter Westwood
> http://blog.ftwr.co.uk | http://westi.wordpress.com
> C53C F8FC 8796 8508 88D6 C950 54F4 5DCD A834 01C5
>
>
> _______________________________________________
> 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