Wordpress 自定义文章类型添加 Categoried、Tags

默认情况下 ,自定义文章类型没有分类和标签属性,需要通过 register_taxonomy_for_object_type 手动注册文章分类和标签,可以通过在 functions.php 或插件中添加如下代码:

add_action( 'init', 'sk_add_category_taxonomy_to_events' );
/**
 * Link `e4gf_events` CPT to categories and tags taxonomies
 */
function sk_add_category_taxonomy_to_events() {
    register_taxonomy_for_object_type( 'category', 'e4gf_events' );
    register_taxonomy_for_object_type( 'post_tag', 'e4gf_events' );
}

e4gf_events 为文章类型

效果如下:

 

资料来源链接:

https://sridharkatakam.com/adding-categories-support-to-a-custom-post-type-in-wordpress/

原文地址:https://www.cnblogs.com/ryanzheng/p/10271750.html