I have created a custom post type 'item':
function mywp_add_item_post() {
$labels = array(
'name' => 'Items',
'singular_name' => 'Item',
'add_new' => 'Add New Item',
'add_new_item' => 'Add New Item',
'edit_item' => 'Edit Item',
'new_item' => 'New Item',
'all_items' => 'All Items',
'view_item' => 'View Item',
'search_items' => 'Search Items',
'not_found' => 'No Items Found',
'not_found_in_trash' => 'No Items found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Items',
'show_in_nav_menus'=>true
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'item'),
'query_var' => true,
'menu_icon' => 'dashicons-randomize',
'show_in_rest' => true,
'show_in_nav_menus'=>true,
'supports' => array('title', 'editor', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'thumbnail', 'author', 'page-attributes'));
register_post_type( 'item', $args );
}
add_action( 'init', 'mywp_add_item_post');
A custom taxonomy named 'collection' is added:
function mywp_add_collection_taxonomy() {
$labels= array('name' => _x( 'Collections', 'taxonomy general name' ),
'singular_name' => _x( 'Collection', 'taxonomy singular name' ),
'search_items' => __( 'Search Collections' ),
'all_items' => __( 'All Collection' ),
'parent_item' => __( 'Parent Collection' ),
'parent_item_colon' => __( 'Parent Collection:' ),
'edit_item' => __( 'Edit Collection' ),
'update_item' => __( 'Update Collection' ),
'add_new_item' => __( 'Add New Collection' ),
'new_item_name' => __( 'New Collection Name' ),
'menu_name' => __( 'Collections' ));
$rewrite= array('slug' => 'collection');
$args= array('hierarchical' => true,
'show_in_nav_menus' => true,
'has_archive' => true,
'labels'=>$labels,
'query_var' => true,
'show_in_rest' => true,
'rewrite'=>$rewrite);
register_taxonomy('collection', 'item', $args);
}
function mywp_tax_filters()
{
register_taxonomy_for_object_type('collection', 'item');
}
add_action('init', 'mywp_add_collection_taxonomy', 1);
add_action('init', 'mywp_tax_filters');
Object: I need a page to view the list of 'collection' that are not empty (like the default categories page)
- A taxonomy template file (taxonomy-collection.php) is created within the theme directory.
- Permalink structure is flushed.
- I have added some 'collections' assigning 'items' inside them.
Problem: The link '$site_url/collection' shows 404 (not found).
Advance thanks for your thoughts on my problem and your patience to read it all through.