WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom post type with it's own taxonomy and I need to display a widget when on a category archive that is ONLY displayed when there are no posts. Currently I'm using this:

 is_tax( 'genre' )    

in the widget logic so that it only displays for that taxonomy but it is being displayed all the time. When there is a post for that category the widget should disappear. Any suggestions?

share|improve this question
is_tax( 'genre' ) && !have_posts() ? – onetrickpony Jul 4 '11 at 2:37
That worked!!!! Thanks so much! – Aaron Jul 4 '11 at 23:16

The have_posts() function checks if the 'main query' returned any posts. is_tax can check if a certain taxonomy archive page is being shown.

In this case, the solution (taken from the comments):

if( is_tax( 'genre' ) && !have_posts() ){
 //Display widget
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.