Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#32272 closed defect (bug) (duplicate)

Built In 'Post' Archive Ignored Using is_post_type_archive()

Reported by: howdy_mcgee's profile Howdy_McGee Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2.1
Component: Query Keywords:
Focuses: administration, template Cc:

Description

I've tested this a couple times and using the built-in post type "Post" archives then testing against is_post_type_archive( 'post' ) always returns false. It does get caught by the catch-all is_archive() on the other-hand.

The expected outcome is when viewing Post Archives to be able to use is_post_type_archive( 'post' ) to specifically target Post Archives.

A quick way to test this is to add this under wp_head()

if( is_post_type_archive( 'post' ) ) {
	die( 'Post Archive' );
} else if( is_archive() ) {
	die( 'All Archives' );
}

Which always evaluates to false on Post Archives.

Change History (4)

#1 follow-up: @SergeyBiryukov
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #23826.

#2 in reply to: ↑ 1 ; follow-up: @Howdy_McGee
9 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Replying to SergeyBiryukov:

Duplicate of #23826.

The linked ticket is not really a duplicate. They're addressing an issue ( over 2 years old ) with is_post_type_archive( 'post' ) working for Front Page or Blog but this issue regards actual Post Archives, Month / Year Archives. There's already is_category() for blog categories, is_tag() for tags, is_author() for Authors, but nothing specifically targets Post Date Archive Pages.

The real issue is that on Month / Year Archive Pages, is_post_type_archive( 'post' ) will always return false on those pages so to target those specific pages you have to use is_archive() which will also catch Post Type Archives. You're forced to have your Post Type Archive conditionals at the top and actual Post Archive is_archive() conditional at the bottom, which even then may catch unintended post type archives.

This isn't documented very well in the Codex or Code Reference and I feel is really a bug.

Last edited 9 years ago by Howdy_McGee (previous) (diff)

#3 in reply to: ↑ 2 @SergeyBiryukov
9 years ago

Replying to Howdy_McGee:

There's an explanation from nacin why is_post_type_archive() works the way it does.

There's already is_category() for blog categories, is_tag() for tags, is_author() for Authors, but nothing specifically targets Post Date Archive Pages.

is_date() does: https://codex.wordpress.org/Function_Reference/is_date.

#4 @Howdy_McGee
9 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

Duplicate of #23826.

Note: See TracTickets for help on using tickets.