カスタム投稿タイプにタグを追加します
-
29-09-2020 - |
質問
WPサイトでチェリーフレームワークを使用しています。それは 'チームメンバー'を追加してスタッフページを作成するために使用することができるカスタム投稿タイプが付属しています。
私はそれを拡大する必要があるので、私はそれぞれの「チームメンバー」にタグを追加することができます。
カスタム投稿タイプは、このコードを使用してtheme-init.phpファイルに登録されています。
/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
)
)
);
}
add_action('init', 'my_post_type_team');
.
これにタグを追加したいので、新しいチームメンバーを追加すると、特定の関連タグを追加することによってそれらを部門に割り当てることもできます。現時点では、タグエディタボックスは追加新規/編集ページに表示されません。
だから、私は上記のコードをこのような登録分類法を含むように適応させた。
/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
)
)
);
register_taxonomy(
'team_tag',
'team',
array(
'hierarchical' => false,
'label' => theme_locals("tags"),
'singular_name' => theme_locals("tag"),
'rewrite' => true,
'query_var' => true
)
);
}
add_action('init', 'my_post_type_team');
.
しかし、adminの編集ページに表示されているタグボックスがまだありません。
これを援助することは非常に高く評価されます。
解決
親/チェリーフレームワークのテーマでTheme-init.phpの一部を上書きしていた子供のテーマのTheme-init.phpになることに問題があるようです。
私の子供のテーマのテーマinit.php;
に次のコードを追加することで問題を解決しました。register_taxonomy('team_tag', 'team', array(
'hierarchical' => false,
'label' => theme_locals("tags"),
'singular_name' => theme_locals("tag"),
'rewrite' => true,
'query_var' => true
)
);
. 他のヒント
これを試してください
register_taxonomy(
'team_tag',
'team',
array(
'hierarchical' => false,
'label' => __( 'Tags', CURRENT_THEME ),
'singular_name' => __( 'Tag', CURRENT_THEME ),
'rewrite' => true,
'query_var' => true
)
);
. register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
),
'taxonomies' => array('team_tag')
)
);
.
taxonomies
ファンクションにregister_post_type
パラメータを追加したことがわかります。
このコードはうまくいくべきですが、後でリレーションを作成することを試みることができます。
add_action('init', 'add_tax_post_rel');
function add_tax_post_rel() {
register_taxonomy_for_object_type('team_tag', 'team', 11);
}
. これを試すことができます
add_action( 'init', 'create_client_tax' );
function create_client_tax() {
register_taxonomy(
'client_tag', //your tags taxonomy
'client', // Your post type
array(
'hierarchical' => false,
'label' => __( 'Tags', CURRENT_THEME ),
'singular_name' => __( 'Tag', CURRENT_THEME ),
'rewrite' => true,
'query_var' => true
)
);
}
.
これはあなたを助けるでしょう
所属していません wordpress.stackexchange