wordpressについて勉強しております。
反映されない原因と、拡張を考えた場合について、
2つアドバイスいただきたいです。
・反映されない原因
ローカルでは実現していますが、サーバ上では反映されませんでした。
wordpressのバージョンはどちらも5.2.2です
投稿ページ右側の
カテゴリv
タグv
アイキャッチ画像v
と並んでいる部分に、
"果物"を追加したいと思っています。
php
1//カスタムタクソノミー 果物 2function create_post_type() { 3 register_taxonomy( 4 'fruits', 5 'post', 6 array( 7 'labels' => array( 8 'name' => '果物', 9 ), 10 'public' => true, 11 'show_ui' => true, 12 'hierarchical' => true, 13 'show_in_rest' => true, 14 )); 15} 16add_action( 'init', 'create_post_type' ); 17 18//カスタムタクソノミー 管理画面 19function add_custom_column( $defaults ) { 20$defaults['fruits'] = '果物'; 21return $defaults; 22} 23add_filter('manage_posts_columns', 'add_custom_column'); 24function add_custom_column_id($column_name, $id) { 25if( $column_name == 'fruits' ) { 26echo get_the_term_list($id, 'fruits', '', ', '); 27} 28} 29add_action('manage_posts_custom_column', 'add_custom_column_id', 10, 2); 30 31//管理画面果物検索追加 32function add_post_restrict_taxonomy() { 33 global $post_type; 34 if ( 'post' == $post_type ) { 35 ?> 36 <select name="fruits"> 37 <option value="">果物一覧</option> 38 <?php 39 $terms = get_terms('fruits'); 40 foreach ($terms as $term) { ?> 41 <option value="<?php echo $term->slug; ?>"><?php echo $term->name; ?></option> 42 <?php } ?> 43 </select> 44 <?php 45 } 46} 47add_action( 'restrict_manage_posts', 'add_post_restrict_taxonomy' ); 48
上記のように記述しております。
グーテンベルグでは
'show_in_rest' => true,
上記記述がないと反映されない、という記事を見つけたので
何か関係あるかと思い関するものを調べてみましたが、分かりませんでした。
・拡張を考えた場合
現在投稿ページをテンプレートを使い
advance custom filed から複数値を取得し作成しているのですが
(ex.生産地、生産者、価格、etc)
タクソノミー"果物"のターム一覧ページ"りんご","桃"等を作る場合、
通常の投稿ページではなく、カスタム投稿を利用したほうがいいのでしょうか?
よろしくお願いいたします。
あなたの回答
tips
プレビュー