[FIXED] Hyphen missing in my Custom Post Type URL Slug

Issue

I have created a new Custom Post Type(Earnings Transcripts) in WordPress using the below code. The name of my Custom Post Type is "Earnings Transcripts" which is 2 words. So the slug should be "earnings-transcripts". Instead the URL is "earningstranscripts". What am I missing here?

function custom_post_type() {
   
    // Earnings Transcripts 
    $labels = array(
        'name'                => _x( 'Earnings Transcripts', 'Post Type General Name', 'twentysixteen' ),
        'singular_name'       => _x( 'Earnings Transcripts', 'Post Type Singular Name', 'twentysixteen' ),
        'menu_name'           => __( 'Earnings Transcripts', 'twentysixteen' ),
        'parent_item_colon'   => __( 'Parent Earnings Transcripts', 'twentysixteen' ),
        'all_items'           => __( 'All Earnings Transcripts', 'twentysixteen' ),
        'view_item'           => __( 'View Earnings Transcripts', 'twentysixteen' ),
        'add_new_item'        => __( 'Add New Earnings Transcripts', 'twentysixteen' ),
        'add_new'             => __( 'Add New', 'twentysixteen' ),
        'edit_item'           => __( 'Edit Earnings Transcripts', 'twentysixteen' ),
        'update_item'         => __( 'Update Earnings Transcripts', 'twentysixteen' ),
        'search_items'        => __( 'Search Earnings Transcripts', 'twentysixteen' ),
        'not_found'           => __( 'Not Found', 'twentysixteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentysixteen' ),
    );
    $args = array(
        'label'               => __( 'Earnings Transcripts', 'twentysixteen' ),
        'description'         => __( 'Earnings Transcripts', 'twentysixteen' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'taxonomies'          => array( 'Earnings Transcripts' ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
    );     
    // Registering your Custom Post Type
    register_post_type( 'Earnings Transcripts', $args );    
    
}
add_action( 'init', 'custom_post_type', 0 );    

Solution

Bit late. I hope this one will be helpful for others who face this scenario.

When it comes to Custom Post types, Slugs should always have underscores instead of hyphens as there are various places in WordPress core that utilize the slugs, and that would break if not using an underscore.

You can check this article for more details on this topic: https://premium.wpmudev.org/forums/topic/why-is-underscore-permitted-in-the-post-type-but-dash-is-disallowed/#post-505820

Answered By – Rajeev

Answer Checked By – Mildred Charles (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published