Archive URL returns 404 error for Custom Post Type

Having issues with a custom post type that returns a 404 error when I visit the archive page.

get_post_type_archive_link() for the post type (called project_profiles) returns the URL mysite.com/project_profiles, however that link produces the 404 error.

If I use the URL mysite.com/post_type=project_profile it correctly loads the index.php template. I do not have an archive.php, but did try creating one to see if it helped (it didn’t).

The custom post type is defined as

function project_profiles_post_type() {

$labels = array(
‘name’ => _x(‘Project Profiles’, ‘Post Type General Name’, ‘text_domain’),
‘singular_name’ => _x(‘Project Profile’, ‘Post Type Singular Name’, ‘text_domain’),
‘menu_name’ => __(‘Project Profiles’, ‘text_domain’),
‘name_admin_bar’ => __(‘Project Profile’, ‘text_domain’),
‘archives’ => __(‘Item Archives’, ‘text_domain’),
‘attributes’ => __(‘Item Attributes’, ‘text_domain’),
‘parent_item_colon’ => __(‘Parent Item:’, ‘text_domain’),
‘all_items’ => __(‘All Items’, ‘text_domain’),
‘add_new_item’ => __(‘Add New Item’, ‘text_domain’),
‘add_new’ => __(‘Add New’, ‘text_domain’),
‘new_item’ => __(‘New Item’, ‘text_domain’),
‘edit_item’ => __(‘Edit Item’, ‘text_domain’),
‘update_item’ => __(‘Update Item’, ‘text_domain’),
‘view_item’ => __(‘View Project Profile’, ‘text_domain’),
‘view_items’ => __(‘View Project Profiles’, ‘text_domain’),
‘search_items’ => __(‘Search Item’, ‘text_domain’),
‘not_found’ => __(‘Not found’, ‘text_domain’),
‘not_found_in_trash’ => __(‘Not found in Trash’, ‘text_domain’),
‘featured_image’ => __(‘Featured Image’, ‘text_domain’),
‘set_featured_image’ => __(‘Set featured image’, ‘text_domain’),
‘remove_featured_image’ => __(‘Remove featured image’, ‘text_domain’),
‘use_featured_image’ => __(‘Use as featured image’, ‘text_domain’),
‘insert_into_item’ => __(‘Insert into Project Profile’, ‘text_domain’),
‘uploaded_to_this_item’ => __(‘Uploaded to this Project Profile’, ‘text_domain’),
‘items_list’ => __(‘Items list’, ‘text_domain’),
‘items_list_navigation’ => __(‘Items list navigation’, ‘text_domain’),
‘filter_items_list’ => __(‘FilterProject Profiles list’, ‘text_domain’),
);
$args = array(
‘label’ => __(‘Project Profile’, ‘text_domain’),
‘description’ => __(‘Metromotion Project Profiles post type’, ‘text_domain’),
‘labels’ => $labels,
‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘revisions’, ‘post-formats’),
‘taxonomies’ => array(‘category’, ‘client’, ‘major_partners’),
‘hierarchical’ => false,
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘menu_position’ => 5,
‘menu_icon’ => ‘data:image/svg+xml;base64,’ . base64_encode(‘<svg version=”1.1″ id=”Layer_1″ xmlns=”http://www.w3.org/2000/svg” xmlns:xlink=”http://www.w3.org/1999/xlink” x=”0px” y=”0px”
viewBox=”0 0 77 74″ style=”enable-background:new 0 0 77 74;” xml:space=”preserve”>
<style type=”text/css”> .st0{fill:#969EA6;}</style><g>
<path class=”st0″ d=”M28.2,49H15.1c-0.8,0-1.5,0.7-1.5,1.5c0,0.8,0.7,1.5,1.5,1.5h13.1c0.8,0,1.5-0.7,1.5-1.5S29,49,28.2,49z”/>
<path class=”st0″ d=”M76.5,54.9L64.6,43.1C67.4,39.8,69,35.6,69,31c0-5.9-2.7-11.2-7-14.7V4c0-2.2-1.8-4-4-4H4C1.8,0,0,1.8,0,4v66
c0,2.2,1.8,4,4,4h54c2.2,0,4-1.8,4-4l0-24.3c0.2-0.1,0.3-0.3,0.5-0.5l11.9,11.8c0.6,0.6,1.5,0.6,2.1,0S77.1,55.5,76.5,54.9z
M46.3,39H36c-1.2-2.1-2-4.5-2.1-7h12.4c0.8,0,1.5-0.7,1.5-1.5S47.1,29,46.3,29H34c0.3-2.6,1.3-5,2.7-7h9.6c0.8,0,1.5-0.7,1.5-1.5
S47.1,19,46.3,19h-7c2.8-2.5,6.5-4,10.6-4c3.4,0,6.5,1,9.1,2.8l0,26.4C56.4,46,53.3,47,49.9,47c-4.6,0-8.7-1.9-11.7-5h8
c0.8,0,1.5-0.7,1.5-1.5S47.1,39,46.3,39z M66,31c0,4-1.5,7.7-4,10.5V20.5C64.5,23.3,66,27,66,31z M59,70c0,0.5-0.5,1-1,1H4
c-0.5,0-1-0.5-1-1V4c0-0.5,0.5-1,1-1h54c0.5,0,1,0.5,1,1v10.3c-2.7-1.4-5.8-2.3-9.1-2.3c-6,0-11.3,2.7-14.8,7h-20
c-0.8,0-1.5,0.7-1.5,1.5s0.7,1.5,1.5,1.5h18c-1.2,2.1-1.9,4.5-2.2,7H15.1c-0.8,0-1.5,0.7-1.5,1.5s0.7,1.5,1.5,1.5h15.8
c0.1,2.5,0.7,4.9,1.7,7H15.1c-0.8,0-1.5,0.7-1.5,1.5s0.7,1.5,1.5,1.5h19.3c3.5,4.8,9.1,8,15.6,8c3.3,0,6.4-0.8,9.1-2.3V70z”/> </g> </svg>’),
‘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’ => ‘page’,
);
register_post_type(‘project_profiles’, $args);
}

add_action(‘init’, ‘project_profiles_post_type’, 0);

I’ve tried changing and resaving permalinks from WordPress setting.

Any help much appreciated.

Read more here:: Archive URL returns 404 error for Custom Post Type

Leave a Reply

Your email address will not be published. Required fields are marked *