1
add_action('init', function() {
    register_post_type('vendorpost', [
        'label' => __('Vendor Post', 'txtdomain'),
        'public' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-admin-users',
        'supports' => ['title', 'editor', 'thumbnail', 'tag', 'revisions', 'comments'],
        'show_in_rest' => true,
        'rewrite' => ['slug' => 'vendorposts'],
        'taxonomies' => ['vendorpost_author', 'vendorpost_genre'],
        'labels' => [
            'singular_name' => __('Vendor Post', 'txtdomain'),
            'add_new_item' => __('Add new vendor post', 'txtdomain'),
            'new_item' => __('New Vendor Post', 'txtdomain'),
            'view_item' => __('View Vendor Post', 'txtdomain'),
            'not_found' => __('No Vendor Post found', 'txtdomain'),
            'not_found_in_trash' => __('No Vendor Post found in trash', 'txtdomain'),
            'all_items' => __('All Vendor Post', 'txtdomain'),
            'insert_into_item' => __('Insert into Vendor Post', 'txtdomain')
        ],      
    ]);
 
    register_taxonomy('vendorpost_category', ['vendorpost'], [
        'label' => __('Categories', 'txtdomain'),
        'hierarchical' => true,
        'rewrite' => ['slug' => 'vendorposts-category'],
        'show_admin_column' => true,
        'show_in_rest' => true,
        'labels' => [
            'singular_name' => __('Category', 'txtdomain'),
            'all_items' => __('All Category', 'txtdomain'),
            'edit_item' => __('Edit Category', 'txtdomain'),
            'view_item' => __('View Category', 'txtdomain'),
            'update_item' => __('Update Category', 'txtdomain'),
            'add_new_item' => __('Add New Category', 'txtdomain'),
            'new_item_name' => __('New Category Name', 'txtdomain'),
            'search_items' => __('Search Categorys', 'txtdomain'),
            'parent_item' => __('Parent Category', 'txtdomain'),
            'parent_item_colon' => __('Parent Category:', 'txtdomain'),
            'not_found' => __('No Category found', 'txtdomain'),
        ]
    ]);
    register_taxonomy_for_object_type('vendorpost_category', 'vendorpost');
 
    register_taxonomy('vendorpost_tag', ['vendorpost'], [
        'label' => __('Tags', 'txtdomain'),
        'hierarchical' => false,
        'rewrite' => ['slug' => 'vendorposts-tag'],
        'show_admin_column' => true,
        'labels' => [
            'singular_name' => __('Tag', 'txtdomain'),
            'all_items' => __('All Tags', 'txtdomain'),
            'edit_item' => __('Edit Tag', 'txtdomain'),
            'view_item' => __('View Tag', 'txtdomain'),
            'update_item' => __('Update Tag', 'txtdomain'),
            'add_new_item' => __('Add New Tag', 'txtdomain'),
            'new_item_name' => __('New Tag Name', 'txtdomain'),
            'search_items' => __('Search Tags', 'txtdomain'),
            'popular_items' => __('Popular Tags', 'txtdomain'),
            'separate_items_with_commas' => __('Separate Tags with comma', 'txtdomain'),
            'choose_from_most_used' => __('Choose from most used Tags', 'txtdomain'),
            'not_found' => __('No Tags found', 'txtdomain'),
        ]
    ]);
    register_taxonomy_for_object_type('vendorpost_tag', 'vendorpost');
});
4
  • i created a archive-vendorposts.php page but when I click on category it redirect to archive.php please help.
    – Lokesh8285
    Feb 19, 2022 at 10:38
  • 1
    Your archive should be archive-vendorpost.php.
    – rudtek
    Feb 20, 2022 at 5:29
  • i using archive-vendorpost.php but not working
    – Lokesh8285
    Feb 21, 2022 at 6:42
  • You should probably include the contents of archive-vendorpost.php as well as the problem may be that it isn't set up correctly. Feb 27, 2022 at 5:28

1 Answer 1

0

If you are wanting to see the archive of you custom posts the archive will be:

archive-vendorpost.php

When you switch to a category there is a separate template wordpress uses:

taxonomy-vendorpost_category.php

Remember also, that you'll need to visit the permalinks page to reset them after as your code doesn't do that for you.

I've tested your code on my system and everything is working properly for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.