Wordpress 自定義文章類型添加 Categoried、Tags
阿新 • • 發佈:2019-01-15
wordpress 技術分享 inf bject add pan com init port
默認情況下 ,自定義文章類型沒有分類和標簽屬性,需要通過 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/
Wordpress 自定義文章類型添加 Categoried、Tags