I have a site on WordPress 3.6.1 and I created a custom post type for recipes with the code:
add_action('init', 'register_cpt_my_recipes');
function register_cpt_my_recipes() {
$args = array(
'hierarchical' => false,
'supports' => array('title', 'editor', 'custom-fields' ,'tag' , 'excerpt', 'thumbnail'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_nav_menus' => false,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
/* Not necessary but added as a solution */
'rewrite'=> array('slug' => 'my_recipes', 'with_front' => true),
'capability_type' => 'post'
);
register_post_type('my_recipes', $args);
/* Not necessary but added as a solution */
flush_rewrite_rules(false);
}
I created archive-my_recipes.php custom template file but whenever I navigate to mysite/my_recipes/ I end up with code from archive.php with all my posts not just posts form my custom post type. I tried taxonomy-my_recipes.php but also didn't work.
Also single-my_recipes.php is working fine. My custom post type's post appear on the main loop.
I read about the subject on the wordpress documentation site here and here I also read answers for similar question here but no working solutions yet.
Also tried the solution here :
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'your-custom-post-type-here'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );