Site logo

Archived topic

Custom post-type Archive & Single Page Showing 404 Error

9 replies · Started by Samuel on March 31, 2021

Viewing posts 1–10 of 10

I have created a custom post-type which name is Portfolio. After creating a post-type I updated Permalink. But When I am going to a custom post-type archive page or single page it's showing a 404 error.

This is the archive page: https://dc1.justcreative.com/portfolio-item/
This is the single page: https://dc1.justcreative.com/portfolio-item/primitive/

Here is the custom post type code:

function jc_portfolio_post_type() {
	$labels = array(
		'name'                  => _x( 'Portfolio', 'Post Type General Name', 'jc' ),
		'singular_name'         => _x( 'Portfolio', 'Post Type Singular Name', 'jc' ),
		'menu_name'             => __( 'Portfolio', 'jc' ),
		'name_admin_bar'        => __( 'Portfolio', 'jc' ),
		'archives'              => __( 'Item Archives', 'jc' ),
		'attributes'            => __( 'Item Attributes', 'jc' ),
		'parent_item_colon'     => __( 'Parent Item:', 'jc' ),
		'all_items'             => __( 'All Items', 'jc' ),
		'add_new_item'          => __( 'Add New Item', 'jc' ),
		'add_new'               => __( 'Add New', 'jc' ),
		'new_item'              => __( 'New Item', 'jc' ),
		'edit_item'             => __( 'Edit Item', 'jc' ),
		'update_item'           => __( 'Update Item', 'jc' ),
		'view_item'             => __( 'View Item', 'jc' ),
		'view_items'            => __( 'View Items', 'jc' ),
		'search_items'          => __( 'Search Item', 'jc' ),
		'not_found'             => __( 'Not found', 'jc' ),
		'not_found_in_trash'    => __( 'Not found in Trash', 'jc' ),
		'featured_image'        => __( 'Featured Image', 'jc' ),
		'set_featured_image'    => __( 'Set featured image', 'jc' ),
		'remove_featured_image' => __( 'Remove featured image', 'jc' ),
		'use_featured_image'    => __( 'Use as featured image', 'jc' ),
		'insert_into_item'      => __( 'Insert into item', 'jc' ),
		'uploaded_to_this_item' => __( 'Uploaded to this item', 'jc' ),
		'items_list'            => __( 'Items list', 'jc' ),
		'items_list_navigation' => __( 'Items list navigation', 'jc' ),
		'filter_items_list'     => __( 'Filter items list', 'jc' ),
	);
	$rewrite = array(
		'slug'                  => 'portfolio-item',
		'with_front'            => true,
		'pages'                 => true,
		'feeds'                 => true,
	);
	$args = array(
		'label'                 => __( 'Portfolio', 'jc' ),
		'description'           => __( 'Post Type Description', 'jc' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'thumbnail', 'revisions' ),
		'taxonomies'            => array( 'portfolio_filter' ),
		'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,
		'rewrite'               => $rewrite,
		'capability_type'       => 'page',
	);
	register_post_type( 'portfolio', $args );
}
add_action( 'init', 'jc_portfolio_post_type', 0 );

Yes, I have created associated templates in Child Theme.

Have you checked your permalink settings ?

My permalink has ok. Please, check this image

My permalink has ok. Please, check this image

Yes, I have cleared Cache from website.

Right now my custom post type slug is portfolio-item. When I am using a prefix with slug (such as new-portfolio-item) then custom post-type Archive & Single Page both page working fine.

Problem just on this slug name portfolio-item.

does your slug and cpt template names match ?

Yes, the template name match with CPT.

Strange that changing the slug makes it work. Maybe you have a conflicting plugin with the portfolio-item slug?

This archived topic is closed to new replies.