'Custom post type single page not working

I have aj-fashions custom post type. technically i tried to show the loop of all post in a template file named fashio-template.php and now for the single post i have created file single-fashions.php. still i am getting 404 error of page not found.

Kindly advice, following is my code.

add_action( 'init', 'fashion' );
function fashion() {
  register_post_type( 'aj-fashion',
    array(
      'labels' => array(
        'name' => __( 'AJ Fasions' ),
        'singular_name' => __( 'AJ Fashion' )
      ),
        'public' => true,
        'has_archive' => true,
        'show_ui' => true,
        'hierarchical' => false,
        'rewrite' => array('slug' => 'aj-fashions',),
        'supports'=> array( 'title', 'editor', 'thumbnail', 'author' ),
    )
  );
}


Solution 1:[1]

I have faced the same issue but it will be resolved by code replaced as below:

function register_fashion() {

    $labels = array(
        'name'                  => 'AJ Fasions',
        'singular_name'         => 'AJ Fasion',
        'menu_name'             => 'AJ Fasions',
        'name_admin_bar'        => 'AJ Fasion',
        'archives'              => 'ajfashionArchives',
        'attributes'            => 'Item Attributes',
        'parent_item_colon'     => 'Parent Item:',
        'all_items'             => 'All Items',
        'add_new_item'          => 'Add New Item',
        'add_new'               => 'Add New',
        'new_item'              => 'New Item',
        'edit_item'             => 'Edit Item',
        'update_item'           => 'Update Item',
        'view_item'             => 'View Item',
        'view_items'            => 'View Items',
        'search_items'          => 'Search Item',
        'not_found'             => 'Not found',
        'not_found_in_trash'    => 'Not found in Trash',
        'featured_image'        => 'Featured Image',
        'set_featured_image'    => 'Set featured image',
        'remove_featured_image' => 'Remove featured image',
        'use_featured_image'    => 'Use as featured image',
        'insert_into_item'      => 'Insert into item',
        'uploaded_to_this_item' => 'Uploaded to this item',
        'items_list'            => 'Items list',
        'items_list_navigation' => 'Items list navigation',
        'filter_items_list'     => 'Filter items list',
    );
    $args = array(
        'label'                 => 'AJ Fasion',
        'description'           => 'Post Type Description',
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
        'taxonomies'            => array( 'fashion_category' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'post',
    );
    register_post_type( 'aj-fashion', $args );
}
add_action( 'init', 'register_fashion', 0 );

Solution 2:[2]

After creating single-{posttype}.php You just update your permalink. Got to Settings->permalinks. First time every developer face this problem.

Solution 3:[3]

After creating single-{posttype}.php You just update your permalink.

And this not worked than use this function

Put in functions.php flush_rewrite_rules( false );

Solution 4:[4]

Use single-{posttype}.php for the single template. Also, if you register your post type with the has_archive argument set to true, then you can use archive-{posttype}.php for your archive template, which will allow you to skip that query that you have there, since the global $wp_query object will already be populated with your custom post type.

In your case check below example

single-fashions.php instead of single-aj-fashion.php.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 melvin
Solution 2 Md Al-Mahmud
Solution 3 hiren panchal
Solution 4 Purvik Dhorajiya