#42764 closed defect (bug) (wontfix)
Template Hierarchy does not work with multiple post types
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.6 |
Component: | Posts, Post Types | Keywords: | close |
Focuses: | template | Cc: |
Description
Inside the "pre_get_posts" action, If you set the post_type argument to multiple, I.E:
<?php add_action( 'pre_get_posts', function($query) { if (!is_admin() && $query->is_main_query() && !$query->is_search() && is_post_type_archive('event')): $query->set('post_type', array( 'event', 'product' ) ); endif; }
This will force the templating hierarchy to use "archive.php" instead of either "archive-event.php" or "archive-product.php"
Currently, I am working around this issue using:
<?php add_filter( "archive_template_hierarchy", function($templates) { $post_types = get_query_var('post_type'); if (count($post_types) > 1 && count($templates) == 1): foreach ($post_types AS $post_type): array_unshift($templates, "archive-".$post_type.".php"); endforeach; endif; return $templates; }, 10, 1 );
Unsure if this is a bug, or intended. Either way, it would be useful to support this.
Change History (4)
#1
in reply to:
↑ description
@
5 years ago
#2
@
5 years ago
- Component changed from Themes to Posts, Post Types
- Keywords close added
- Version changed from 4.9.1 to 3.6
Note: See
TracTickets for help on using
tickets.
Replying to nbdamian:
This could be resolved by changing template.php line 114 from
To: