Reputation: 87
I have looking for this issue for 2 days and now decide to put my question here so that i can have proper solution or guidance. I have gone through similar questions on stackoverflow
but some have solution that did not work for me.. and some yet have not proper answer.
Please go through my code and tell me if there is any mistake I am doing..
I have custom post type of infographics
and have added a taxonomy
infograph_category
to it. code is below.
// For Infograph Custom Post Type
function mtc_custom_post_type_infographs() {
/**
* Post Type: Infographs.
*/
$labels = array(
"name" => __( "Infographs", "" ),
"singular_name" => __( "Infograph", "" ),
);
$args = array(
"label" => __( "Infographs", "" ),
"labels" => $labels,
"description" => "All the infographic content will be posted with this type of post",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "infographics", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail", "excerpt" ),
"taxonomies" => array( "infograph_category" ),
);
register_post_type( "infographics", $args );
}
add_action( 'init', 'mtc_custom_post_type_infographs' );
function mtc_infograph_categories() {
/**
* Taxonomy: infograph categories.
*/
$labels = array(
"name" => __( "infograph categories", "" ),
"singular_name" => __( "infograph_category", "" ),
"all_items" => __( "All Infograph Categories", "" ),
"edit_item" => __( "Edit infograph category", "" ),
"view_item" => __( "View infograph category", "" ),
"update_item" => __( "Update infograph category", "" ),
"add_new_item" => __( "Add infograph category", "" ),
"new_item_name" => __( "New infograph category", "" ),
"parent_item" => __( "Parent infograph category", "" ),
"parent_item_colon" => __( "Parent infograph category", "" ),
"search_items" => __( "Search infograph categories", "" ),
"popular_items" => __( "Popular infograph categories", "" ),
"add_or_remove_items" => __( "Add or remove infograph categories", "" ),
"not_found" => __( "No infograph category found", "" ),
"no_terms" => __( "No infograph categories", "" ),
);
$args = array(
"label" => __( "infograph categories", "" ),
"labels" => $labels,
"public" => true,
"hierarchical" => false,
"label" => "infograph categories",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => array( 'slug' => 'infograph_category', 'with_front' => true, ),
"show_admin_column" => false,
"show_in_rest" => false,
"rest_base" => "infograph_category",
"show_in_quick_edit" => false,
);
register_taxonomy( "infograph_category", array( "infographics" ), $args );
}
add_action( 'init', 'mtc_infograph_categories' );
Note: This code is actually generated by CPT plugin
I have created templates for single and category pages like, for single its single-infographics.php
and for category its taxonomy-infograph_category.php
and both templates are working fine. But now I want to create a template in which all the post from custom post type infographs
should shown in there.
I tried creating some templates like
archive-infographs.php
taxonomy-infographs.php
taxonomy-infograph_categories.php
archive-infograph_categories.php
but nothing works.
I just need a guidance where I am wrong are what is wrong with this code. Please do not discourage this post, as I have already mentioned that I have gone through lots of questions and googled alot.. but after I failed to get any proper solution for my problem I am posting this is here! Hope you understand and I will get proper guidance/solution!
Thanks
Upvotes: 1
Views: 4839
Reputation: 1097
if you go through CPT UI plugins settings in Registered Types/Taxes
you can find exactly what you need, like template hierarchy.
just change the value of has_archive
from False
to True
and see template hierarchy in CPT UI plugins. you will find all the required templates for each type.
Upvotes: 1