Here's my issue:
I have assigned a custom post type to certain categories. When I search for these categories, either through search or entering the url directly. However, if I assign a normal post type to a category, it becomes searchable and can be entered by the url directly. I thought I got everything in my custom post type code, but I must have missed something. Any help would be appreciated:
add_action('init', 'create_trainingplan_post_type');
function create_trainingplan_post_type() {
register_post_type('trainingplan', array(
'labels' => array(
'name' => 'Training Plans',
'singular_name' => 'Training Plan',
'add_new' => 'Add New Training Plan',
'add_new_item' => 'Add New Training Plan',
'edit' => 'Edit Training Plans',
'edit_item' => 'Edit Training Plan',
'new_item' => 'New Training Plan',
'view_item' => 'View Training Plans',
'search_items' => 'Search Training Plans',
'not_found' => 'No Training Plans found',
'not_found_in_trash' => 'No Training Plans found in Trash'
),
'public' => true,
'exclude_from_search'=> false,
'rewrite' => array('slug' => 'my-custom-training-plan', 'with_front' => true),
'supports' => array(
'title',
'excerpt',
'editor',
'custom-fields',
'revisions',
'thumbnail',
'author',
'page-attributes'
),
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
));
flush_rewrite_rules();
}
Thank you for the help so far, I've added comments from the answer I received so far to make it more clear in my question:
@ בניית אתרים I can actually search for the custom post type and find it. It's that the categories that are assigned only to custom post types cannot be searched or found. Basically, I am trying to enable a user to search by category, but categories that are assigned to only a custom post type are not appearing. For that matter, even if I type in the direct url of the category, it takes me to an error page: "Sorry, we can't find the category you're looking for at this URL. Please try selecting a menu item from above or to the side of this message to get where you..."
@ בניית אתרים I assigned the categories to the custom post type like you would a normal post. While writing the post, I ticked the categories I wanted included. When in the edit posts dashboard, it does confirm that categories are assigned to the cpt. However, when I go to the category url or search for posts within that category, cpt do not show.
Thanks again
flush_rewrite_rules();
inside an action run on init, it will cause the rules to flush on every page.