March 06, 2019
If you’ve run into an error where your site is loading all of your Pages as Blog or Archive.
Check your functions.php file to see if there is conflicting information with taxonomies relating to your Custom Post Types, or the theme default post type names. Using taxonomy or post type slugs that already exist in the WordPress template (e.g., year, month, date, post, etc.), and updating permalinks, can cause the website to return the Archive (Blog) template for all Pages.
Additional cause could be if your Custom Post Type is not hierarchical and your Taxonomy is.
See below for more information.
add_action( 'init', 'create_post_type' ); function create_post_type() { $labels = array( 'name' => _x('Speakers', 'post type general name'), 'singular_name' => _x('Speaker', 'post type singular name'), 'add_new' => _x('Add New Speaker', 'Speaker'), 'add_new_item' => __('Add New Speaker'), 'edit_item' => __('Edit Speaker'), 'new_item' => __('New Speaker'), 'all_items' => __('All Speakers'), 'view_item' => __('View Speaker'), 'search_items' => __('Search Speakers'), 'not_found' => __('No Speakers found'), 'not_found_in_trash' => __('No Speakers found in Trash'), 'parent_item_colon' => '', 'menu_name' => __('Speakers'), 'taxonomy' => array('speaker_year'), // relate the taxonomy to the custom post type ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, // set to true 'menu_position' => null, 'supports' => array( 'title', 'revisions', 'thumbnail', 'editor' ), 'exclude_from_search' => false, ); register_post_type('speaker',$args); }
Taxonomy:
add_action ( 'init', 'main_taxonomy' ); function main_taxonomy() { register_taxonomy( 'speaker_year', array('speaker'), array( 'label' => __( 'Year' ), 'rewrite' => array( 'slug' => 'speaker_year' ), 'hierarchical' => true, // set above to true or remove this line 'show_ui' => true, 'show_in_menu' => true, 'show_admin_column' => true, ) ); }