1. 程式人生 > >Wordpress 自定義文章類型添加 Categoried、Tags

Wordpress 自定義文章類型添加 Categoried、Tags

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