2017-10-27 46 views
3

Personのカスタムポストタイプとタクソノミを設定しました。名前をPeopleに変更したいと思うまで、私はかなりの投稿を追加しました。私が加えた投稿は消えてしまったので、正しい投稿タイプに投稿を再割り当てしなければならなかった。Wordpress - カスタム投稿タイプの混乱 - タクソノミーが表示されない

私が今問題にしているのは、タクソノミが表示されていないということです(場所と職務機能)。それらは登録されていないようで、メニューやカスタムタイプの投稿ページには表示されません。

permalinkをリセットしてflush_rewrite_rules()を使用しました。まだ何もない。誰も助けることができますか?

<?php 

/** 
* People post type & taxonomies 
* 
* Post Type: people 
* Taxonomies: function 
*    
*/ 


add_action('init', 'create_people_post_type', 5); 
function create_people_post_type() { 


    flush_rewrite_rules(); 

    register_post_type('People', 
     [ 
      'labels' => [ 
       'name' => __('People'), 
       'singular_name' => __('People'), 
      ], 
      'public' => true, 
      'has_archive' => true, 
      'supports' => ['title', 'thumbnail', 'author' ], 
     ] 
    ); 

    register_taxonomy(
     'job-functions', 
     'People', 
     [ 
      'labels' => [ 
       'name' => __('Job Functions'), 
       'singular_name' => __('Job Function'), 
      ], 
      'hierarchical' => true, 
      'show_admin_column' => true, 
     ] 
    ); 

} 

add_action('init','add_locations_to_people'); 
function add_locations_to_people(){ 
    register_taxonomy_for_object_type('location', 'People'); 
} 

}

<?php 
/** 
* Location post type 
* 
* Post Type: location 
* 
*    
*/ 
    add_action('init', 'create_office_location_post_type', 4); 
    function create_office_location_post_type() { 
     register_post_type('location', 
      [ 
       'labels' => [ 
        'name' => __('Office Locations'), 
        'singular_name' => __('Office Location'), 
       ], 
       'public' => true, 
       'has_archive' => true, 
       'supports' => [ 'title', 'author' ], 
      ] 
     ); 
    } 

    ?> 

答えて

0

新しい投稿タイプを登録すると、あなたはそれを持っていると思われる分類法を設定する必要があります。

register_post_type('People', 
     [ 
      'labels' => [ 
       'name' => __('People'), 
       'singular_name' => __('People'), 
      ], 
      'public' => true, 
      'taxonomies'=>array('job-functions'), 
      'has_archive' => true, 
      'supports' => ['title', 'thumbnail', 'author' ], 
     ] 
    ); 

UPD:ここ

は、あなたのケースのための最終的なコードです。最初に指定したコードでは、まず投稿タイプを登録し、既に登録されている投稿タイプに分類法を追加しようとします。だから、彼らの場所を置き換えるだけでいいです。

add_action('init', 'create_people_post_type', 5); 
function create_people_post_type() { 
    flush_rewrite_rules(); 
    register_taxonomy(
     'job-functions', 
     'People', 
     [ 
      'labels' => [ 
       'name' => __('Job Functions'), 
       'singular_name' => __('Job Function'), 
      ], 
      'hierarchical' => true, 
      'show_admin_column' => true, 
     ] 
    ); 
    register_post_type('People', 
     [ 
      'labels' => [ 
       'name' => __('People'), 
       'singular_name' => __('People'), 
      ], 
      'public' => true, 
      'taxonomies'=>array('job-functions'), 
      'has_archive' => true, 
      'supports' => ['title', 'thumbnail', 'author' ], 
     ] 
    ); 
} 
add_action('init','add_locations_to_people'); 
function add_locations_to_people(){ 
    register_taxonomy_for_object_type('location', 'People'); 
} 

UPD2:

add_action('init', 'create_people_post_type', 5); 
function create_people_post_type() { 
    flush_rewrite_rules(); 
    register_taxonomy(
     'job-functions', 
     'People', 
     [ 
      'labels' => [ 
       'name' => __('Job Functions'), 
       'singular_name' => __('Job Function'), 
      ], 
      'hierarchical' => true, 
      'show_admin_column' => true, 
     ] 
    ); 

    register_taxonomy(
     'location', 
     'People', 
     [ 
      'labels' => [ 
       'name' => __('Location'), 
       'singular_name' => __('Location'), 
      ], 
      'hierarchical' => true, //true if it is category like, false if it is tag like 
      'show_admin_column' => true, 
     ] 
    ); 
    register_post_type('People', 
     [ 
      'labels' => [ 
       'name' => __('People'), 
       'singular_name' => __('People'), 
      ], 
      'public' => true, 
      'taxonomies'=>array('job-functions','location'), 
      'has_archive' => true, 
      'supports' => ['title', 'thumbnail', 'author' ], 
     ] 
    ); 
} 
+0

は現在表示されていることをしようとしましたが、残念ながら – LeeTee

+0

が動作するコード –

+0

こんにちはと私の更新の答えをチェックしてください動作しません、私たちは「仕事関数」などが半分の方法であるようですしかし、「場所」はそうではありません。私はタクソノミーの配列に 'location'を追加しようとしましたが、うまくいきません。 – LeeTee

関連する問題