[wp-testers] Conditional tags not working

Peter Westwood peter.westwood at ftwr.co.uk
Sun Jan 17 11:02:38 UTC 2010


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



More information about the wp-testers mailing list