I created my Custom Post Type (bizdirectory), created a new post (Test Business) and created a new category (Business Directory). But if I add the Business Directory category (slug = business) to my Primary Navigation, the link shows, it registers as the category, but it says “nothing found”.
If I search my site (using the search bar on the front page) for Test Business it finds it – the URL it shows is – http://www.domain.com/dev/?bizdirectory=test-business – my code for functions.php is below:
// Load Custom Post Type
function add_bizdirectory() {
$labels = array(
'name' => __( 'Businesses', 'text_domain' ),
'singular_name' => __( 'Business', 'text_domain' ),
'add_new' => __( 'Add New Business', '${4:Name}', 'text_domain' ),
'add_new_item' => __( 'Add New Business', 'text_domain}' ),
'edit_item' => __( 'Edit Business', 'text_domain' ),
'new_item' => __( 'New Business', 'text_domain' ),
'view_item' => __( 'View Business', 'text_domain' ),
'search_items' => __( 'Search Businesses', 'text_domain' ),
'not_found' => __( 'No Businesses found', 'text_domain' ),
'not_found_in_trash' => __( 'No Businesses found in Trash', 'text_domain' ),
'parent_item_colon' => __( 'Parent Business:', 'text_domain' ),
'menu_name' => __( 'Business Directory', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'description',
'taxonomies' => array( 'category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'revisions', 'post-formats' ),
);
register_post_type( 'bizdirectory', $args );
}
add_action( 'init', 'add_bizdirectory' );
// End
I have tried all of the rewrite rules options apart from the one where I manually delete the rewrite rules from wp_options – it didn’t appear in wp_options.
I appreciate any help or advice that you could give me 🙂
You are better off separating categories for posts and using custom taxonomy types for CPT categories.
You’d add this line to your register cpt code
Replacing this line in your code.
And then add this code in your functions.php
I have found the answer, I had completely misunderstood the differences between standard post types and custom post types, as well as their taxonomies. I found several very helpful articles and the code below is what I ended up with, as well as a few of the articles that I found helpful. I hope others find this useful.