[wp-trac] [WordPress Trac] #59422: Custom Post Type name with hyphen does not with custom single post template

WordPress Trac noreply at wordpress.org
Thu Sep 21 09:25:05 UTC 2023


#59422: Custom Post Type name with hyphen does not with custom single post template
--------------------------+------------------------------
 Reporter:  htung         |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Themes        |     Version:  6.3.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  template
--------------------------+------------------------------

Comment (by htung):

 @faisal03 As checking on the code, it is normal hyphen. The "annual-
 report" CPT is working normally at other functionalities, such as
 add/editing/listing post but when comes to calling in single post theme
 file is not linked.

 Code below is part of post type registration:

 {{{#!php
 <?php
 $postTypeName = normalize_whitespace(strtolower(preg_replace("/[^A-Za-z0-9
 ]/", '-', 'annual-report')));
 $postTypeNames[$postTypeName] = $postType->post_title;
 $entMetabox->postType = $postTypeName;

 $args =  array(
         'labels' => array(
                 'name' => __($postType->post_title),
                 'singular_name'      => __( $postType->post_title),
                 'menu_name'          => __( $postType->post_title . 's'),
                 'name_admin_bar'     => __( $postType->post_title . 's'),
                 'add_new'            => __( 'Add New'),
                 'add_new_item'       => __( 'Add New ' .
 $postType->post_title),
                 'edit_item'          => __( 'Edit ' .
 $postType->post_title),
                 'new_item'           => __( 'New Example'),
                 'view_item'          => __( 'View ' .
 $postType->post_title),
                 'search_items'       => __( 'Search
 '.$postType->post_title.'s'),
                 'not_found'          => __( 'No '.$postType->post_title.'s
 found'),
                 'not_found_in_trash' => __( 'No '.$postType->post_title.'s
 found in trash'),
                 'all_items'          => __( 'All
 '.$postType->post_title.'s'),

                 /* Labels for hierarchical post types only. */
                 'parent_item'        => __( 'Parent
 '.$postType->post_title),
                 'parent_item_colon'  => __( 'Parent
 '.$postType->post_title.':'),

                 /* Custom archive label.  Must filter
 'post_type_archive_title' to use. */
                 'archive_title'      => __( $postType->post_title . 's'),
         ),
         'supports' => isset($postType->{'supports'})
                 ? $postType->{'supports'}
                 : array(
                         'title',
                         'editor',
                         // 'excerpt',
                         // 'custom-fields',
                         // 'page-attributes',
                         'thumbnail',
                         ),
         'public' => isset($postType->{'public'}) ? $postType->{'public'} :
 true,
         'show_in_rest' => isset($postType->{'show_in_rest'}) ?
 $postType->{'show_in_rest'} : false, /* Enable to have Gutenberg editor.
 */
         'show_in_menu' => $parentPath,
         'taxonomies' => isset($postType->{'taxonomies'}) ?
 array_map('trim',explode(',',$postType->{'taxonomies'})) :
 array('post_tag','category'),
         'show_ui' => isset($postType->{'show_ui'}) ?
 $postType->{'show_ui'} : true,
         'capability_type'     => array( $postTypeName, $postTypeName.'s'),
 /** Add controller for user roles */
         'map_meta_cap'        => isset($postType->{'map_meta_cap'}) ?
 $postType->{'map_meta_cap'} : true, /** Add controller for user roles */
         'menu_position' =>  10,
         'menu_icon' => isset($postType->{'menu_icon'}) ?
 $postType->{'menu_icon'} : 'dashicons-format-aside'
 );

 register_post_type( $postTypeName, $args);
 }}}

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


More information about the wp-trac mailing list