[wp-trac] [WordPress Trac] #41564: Search for hyphenated post templates for post types with underscores

WordPress Trac noreply at wordpress.org
Sun Sep 21 14:05:53 UTC 2025


#41564: Search for hyphenated post templates for post types with underscores
-------------------------------------------------+-------------------------
 Reporter:  desrosj                              |       Owner:  (none)
     Type:  feature request                      |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Themes                               |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-test-info needs-patch needs-     |     Focuses:
  unit-tests                                     |
-------------------------------------------------+-------------------------
Changes (by SirLouen):

 * keywords:  dev-feedback has-patch needs-testing => has-test-info needs-
     patch needs-unit-tests
 * focuses:  template =>
 * component:  Posts, Post Types => Themes


Comment:

 == Test Report
 === Description
 ❌ This report can't fully validate that the indicated patch works as
 expected.

 Patch tested: https://github.com/WordPress/wordpress-develop/pull/9973

 === Environment
 - WordPress: 6.9-alpha-60093-src
 - PHP: 8.2.29
 - Server: nginx/1.29.1
 - Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
 - Browser: Chrome 139.0.0.0
 - OS: Windows 10/11
 - Theme: Twenty Twenty-Five 1.3
 - MU Plugins: None activated
 - Plugins:
   * BBB Testing Dolly
   * Test Reports 1.2.0

 === Testing Instructions
 There are 3 separate tests here

 ==== Test Taxonomy Template
 1. Add the code provided in Supp Artifacts
 2. Create a term in Foo Bar for example "Sample Term"
 3. Visit that Term, check the debug log.

 🐞 Without the patch
 {{{
 [0] => taxonomy-foo_bar-sample-term.php
 [1] => taxonomy-foo_bar.php
 [2] => taxonomy.php
 }}}

 ⚠️ With the patch:

 {{{
 [0] => taxonomy-foo_bar-sample-term.php
 [1] => taxonomy-foo-bar.php
 [2] => taxonomy-foo_bar.php
 [3] => taxonomy.php
 }}}

 ==== Test Post Type
 1. Edit the code provided in Supp Artifacts to adapt to post types (need
 to register a post_type in this case)
 2. Create a post in Foo Bar post type for example "Sample Post Type"
 3. Visit that post in this new Post Type

 🐞 Without the patch
 {{{
 [0] => single-foo_bar-sample-post-type.php
 [2] => single-foo_bar.php
 [3] => single.php
 }}}

 ⚠️ With the patch:

 {{{
 [0] => single-foo_bar-sample-post-type.php
 [1] => single-foo-bar.php
 [2] => single-foo_bar.php
 [3] => single.php
 }}}

 === Actual Results
 1. ❌ Issue is not resolved with patch.

 === Additional Notes
 - Without the patch, there is no priority for the file without hyphens
 - ⚠️ But the patch doesn't cover the template in case of targeting a
 specific term. In this case, the correct form should be full hyphened, for
 example `taxonomy-foo-bar-sample-term.php` following the same scenario
 provided in OP
 - Given that the patch was done like 8+ years ago, I'm going to demote it
 to `needs-patch` as a whole new version is needed, but if you are willing
 to do a new patch take my [https://github.com/WordPress/wordpress-
 develop/pull/9973 PR 9973] as a reference.
 - One unit tests for each of the 3 forms will be good also.

 === Supplemental Artifacts

 Taxonomy Testing
 {{{#!php
 <?php
 add_action( 'init', 'register_test_taxonomy' );
 function register_test_taxonomy() {
         register_taxonomy(
                 'foo_bar',
                 'post',
                 array(
                         'label'        => 'Foo Bar',
                         'public'       => true,
                         'show_ui'      => true,
                         'show_in_rest' => true,
                 )
         );
 }
 add_filter( 'taxonomy_template_hierarchy', 'log_taxonomy_hierarchy' );
 function log_taxonomy_hierarchy( $templates ) {
         if ( is_tax( 'foo_bar' ) ) {
                 error_log( 'taxonomy_template_hierarchy => ' . print_r(
 $templates, true ) );
         }
         return $templates;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/41564#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list