WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 19 months ago

#38910 new defect (bug)

`is_post_type_archive()` return true when the current page is tag archive

Reported by: yaquawa Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.6.1
Component: General Keywords: reporter-feedback close
Focuses: template Cc:

Description

See if you register a post type "fruit". And you have a tag "sample-tag".

When you access:
http://localhost/tag/sample-tag/?post_type=fruit

You'll be taken to the post type archive page(template) rather than the tag archive page even the URL is telling you this is a tag archive page.

This is because the is_post_type_archive() is called earlier than is_tag() in wp-includes/template-loader.php. It should never depend on the order of condifional functions be called, I believe this is a serious bug.

is_post_type_archive() should return false when the current page is NOT a post type archive page.

To get a stricter result of is_post_type_archive(), it should check if the current queried_object is a WP_Post type or not.
If you are viewing a tag archive, the queried_object is an instance of WP_Term , obviously, this is NOT a "post type archive" page at all.

Change History (2)

#1 in reply to: ↑ description @yaquawa
4 years ago

Seems like I can't edit my ticket after I've submitted it?

I'm sorry, but I want to correct my ticket:

To get a stricter result of is_post_type_archive(), it should check if the current queried_object is a WP_Post type or not.


To get a stricter result of is_post_type_archive(), it should check if the current queried_object is a WP_Post_Type type or not.

#2 @desrosj
19 months ago

  • Keywords reporter-feedback close added

Hi @yaquawa,

First, my apologies it took so long to get a response to this ticket.

Are you still experiencing this behavior with the latest version of WordPress? If so, can you provide more details about which theme you experienced this with? Are you sure that the theme was not giving priority to is_tag() and not is_post_type_archive()? In my testing using Twenty Seventeen and Twenty Nineteen, both of those conditional functions return true.

Marking this as a candidate to close as a worksforme pending more details.

Note: See TracTickets for help on using tickets.