Site icon Hip-Hop Website Design and Development

WordPress not respecting template hierarchy

I have been trying for hours to figure out why WP keeps using single.php for my CPT.

Here is the code for the CPT:

<?php
add_action( 'init', 'your_prefix_register_post_type' );
function your_prefix_register_post_type() {
    $labels = [
        'name'                     => esc_html__( 'Listings', 'your-textdomain' ),
        'singular_name'            => esc_html__( 'Listing', 'your-textdomain' ),
        'add_new'                  => esc_html__( 'Add New', 'your-textdomain' ),
        'add_new_item'             => esc_html__( 'Add new listing', 'your-textdomain' ),
        'edit_item'                => esc_html__( 'Edit Listing', 'your-textdomain' ),
        'new_item'                 => esc_html__( 'New Listing', 'your-textdomain' ),
        'view_item'                => esc_html__( 'View Listing', 'your-textdomain' ),
        'view_items'               => esc_html__( 'View Listings', 'your-textdomain' ),
        'search_items'             => esc_html__( 'Search Listings', 'your-textdomain' ),
        'not_found'                => esc_html__( 'No listings found', 'your-textdomain' ),
        'not_found_in_trash'       => esc_html__( 'No listings found in Trash', 'your-textdomain' ),
        'parent_item_colon'        => esc_html__( 'Parent Listing:', 'your-textdomain' ),
        'all_items'                => esc_html__( 'All Listings', 'your-textdomain' ),
        'archives'                 => esc_html__( 'Listing Archives', 'your-textdomain' ),
        'attributes'               => esc_html__( 'Listing Attributes', 'your-textdomain' ),
        'insert_into_item'         => esc_html__( 'Insert into listing', 'your-textdomain' ),
        'uploaded_to_this_item'    => esc_html__( 'Uploaded to this listing', 'your-textdomain' ),
        'featured_image'           => esc_html__( 'Featured image', 'your-textdomain' ),
        'set_featured_image'       => esc_html__( 'Set featured image', 'your-textdomain' ),
        'remove_featured_image'    => esc_html__( 'Remove featured image', 'your-textdomain' ),
        'use_featured_image'       => esc_html__( 'Use as featured image', 'your-textdomain' ),
        'menu_name'                => esc_html__( 'Listings', 'your-textdomain' ),
        'filter_items_list'        => esc_html__( 'Filter listings list', 'your-textdomain' ),
        'filter_by_date'           => esc_html__( '', 'your-textdomain' ),
        'items_list_navigation'    => esc_html__( 'Listings list navigation', 'your-textdomain' ),
        'items_list'               => esc_html__( 'Listings list', 'your-textdomain' ),
        'item_published'           => esc_html__( 'Listing published', 'your-textdomain' ),
        'item_published_privately' => esc_html__( 'Listing published privately', 'your-textdomain' ),
        'item_reverted_to_draft'   => esc_html__( 'Listing reverted to draft', 'your-textdomain' ),
        'item_scheduled'           => esc_html__( 'Listing scheduled', 'your-textdomain' ),
        'item_updated'             => esc_html__( 'Listing updated', 'your-textdomain' ),
        'text_domain'              => esc_html__( 'your-textdomain', 'your-textdomain' ),
    ];
    $args = [
        'label'               => esc_html__( 'Listings', 'your-textdomain' ),
        'labels'              => $labels,
        'description'         => 'This post type is for property listings.',
        'public'              => true,
        'hierarchical'        => false,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'show_ui'             => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'show_in_rest'        => true,
        'query_var'           => true,
        'can_export'          => true,
        'delete_with_user'    => true,
        'has_archive'         => false,
        'rest_base'           => '',
        'show_in_menu'        => true,
        'menu_position'       => 4,
        'menu_icon'           => 'dashicons-admin-network',
        'capability_type'     => 'post',
        'supports'            => ['title', 'editor', 'thumbnail'],
        'taxonomies'          => ['post_tag'],
        'rewrite'             => [
            'with_front' => false,
        ],
    ];

    register_post_type( 'listing', $args );
}

My template file name is single-listing.php; I have cleared my cache and saved the permalinks several times. I am using Metabox for the CPT, but I even disabled it and pasted the above code into the functions.php file, but nothing changed. I’m like 99% sure everything is the way it should be.

Please help!

UPDATE: For the time being, I did an IF statement using the get_post_type call, then did include it for the template I want to be based on the slug. I’d still like to investigate this with someone if willing.