最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Custom Post Archive Page not working

programmeradmin2浏览0评论
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');
});
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');
});
Share Improve this question edited Feb 20, 2022 at 5:12 Lokesh8285 asked Feb 19, 2022 at 10:36 Lokesh8285Lokesh8285 112 bronze badges 4
  • i created a archive-vendorposts.php page but when I click on category it redirect to archive.php please help. – Lokesh8285 Commented Feb 19, 2022 at 10:38
  • 1 Your archive should be archive-vendorpost.php. – rudtek Commented Feb 20, 2022 at 5:29
  • i using archive-vendorpost.php but not working – Lokesh8285 Commented 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. – Tony Djukic Commented Feb 27, 2022 at 5:28
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论