WordPress 4.4 introduced the ability to display date archives by appending /?post_type=custom_post_type to the end of the date url. i.e. localhost/2016/02/?post_type=news.

I had assumed I could do: if( is_post_type_archive('news) && is_date())...

But from what I can discern:

  • is_date() will only detect if the page is displaying a year/month/day archive & is_date() applies to all CPT date archives as well

  • is_archive() applies to all archive pages

  • is_post_type_archive('CPT') will only apply to the archive page and filters out date archives

I'm trying to output a menu on the news date archive pages to display separately from the blog date archive pages.


1 Answer 1


There is no logical explanation why if( is_post_type_archive('news) && is_date()) should fail and not work in your situation.

  • is_date() return true on all date archives

  • is_post_type_archive( 'news' ) will return true on post type archives

When you visit localhost/2016/02/?post_type=news, both of those ring true, and they will only ring true on that specific URL

If it it fails, you have something breaking your main query, maybe a bad pre_get_posts action or you are using query_posts somewhere on the page which will break the main query object. You should do var_dump( $wp_query ) and inspect the main query object. Specially look at $query property

  • You are correct. I just re-ran this through a fresh install with the following: <?php if(is_date() && is_post_type_archive('news')) { echo 'is_date + is_post_type_archive(news)'; } elseif( is_date() && is_post_type_archive('posts')) { echo ' is_date + is_post_type_archive(posts)'; } elseif( is_date() && is_archive()) { echo ' is_date + is_archive'; } ?> and it produced: localhost/2016/ : is_date + is_archive localhost/2016/?post_type=news : is_date + is_post_type_archive(news) localhost/2016/?post_type=post : is_date + is_archive
    – ZachTRice
    Commented Feb 26, 2016 at 5:29
  • Glad it worked. Enjoy ;-) Commented Feb 26, 2016 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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