I use a custom post type, which also should have a custom taxonomy. When I visit the archive page /kollektion/ I can see all items of this CPT, when I visit /kollektion/mytaxonomy1/ I can see all items which are assigned to this taxonomy.
When I click on the single item of the custom post type, I get a 404 error. I also tried to go into my WP dashboard and change and resave the permalinks again - with no success.
Does anybody see an error in my declaration which causes the 404 error on single pages of my custom post type?
Thanks.
functions.php: Taxonomy
// register two taxonomies to go with the post type
function sm_register_taxonomy() {
// set up labels
$labels = array(
'name' => 'Kollektionen Categories',
'singular_name' => 'Kollektion Category',
'search_items' => 'Search Kollektion Categories',
'all_items' => 'All Kollektion Categories',
'edit_item' => 'Edit Kollektion Category',
'update_item' => 'Update Kollektion Category',
'add_new_item' => 'Add New Kollektion Category',
'new_item_name' => 'New Kollektion Category',
'menu_name' => 'Kollektion Categories'
);
// register taxonomy
register_taxonomy( 'kollektionen', 'kollektion', array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'kollektion', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
),
) );
}
add_action( 'init', 'sm_register_taxonomy' );
functions.php: Custom post type
// Register Custom Post Type Kollektion
function post_type_kollektion() {
$labels = array(
'name' => _x( 'Kollektionen', 'Post Type General Name', 'genesis' ),
'singular_name' => _x( 'Kollektion', 'Post Type Singular Name', 'genesis' ),
'menu_name' => __( 'Kollektion', 'genesis' ),
'name_admin_bar' => __( 'Kollektion', 'genesis' ),
'parent_item_colon' => __( 'Parent Item:', 'genesis' ),
'all_items' => __( 'All Items', 'genesis' ),
'add_new_item' => __( 'Add New Item', 'genesis' ),
'add_new' => __( 'Add New', 'genesis' ),
'new_item' => __( 'New Item', 'genesis' ),
'edit_item' => __( 'Edit Item', 'genesis' ),
'update_item' => __( 'Update Item', 'genesis' ),
'view_item' => __( 'View Item', 'genesis' ),
'search_items' => __( 'Search Item', 'genesis' ),
'not_found' => __( 'Not found', 'genesis' ),
'not_found_in_trash' => __( 'Not found in Trash', 'genesis' ),
'items_list' => __( 'Items list', 'genesis' ),
'items_list_navigation' => __( 'Items list navigation', 'genesis' ),
'filter_items_list' => __( 'Filter items list', 'genesis' ),
);
$args = array(
'label' => __( 'Kollektion', 'genesis' ),
'description' => __( 'Kollektionen', 'genesis' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', ),
'taxonomies' => array( 'post_tag', 'kollektionen' ),
'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' => 'kollektion',
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'kollektion', $args );
}
add_action( 'init', 'post_type_kollektion');
}
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'kollektion', 'kollektionen'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
It looks like you have the same slug for taxonomy and custom post type. Try to change slug of taxonomy (or CPT) and resave the permalinks - this should help.