WordPress - Пользовательские таксономии не отображаются в меню «Внешний вид»> «Меню» - PullRequest
0 голосов
/ 07 октября 2019

У меня есть пользовательский тип записи под названием Resources :

register_post_type(
    'resources',
    build_post_args(
        'resources', 'Resource', 'Resources',
        array(
            'menu_icon'     => 'dashicons-welcome-write-blog',
            'menu_position' => 20,
            'has_archive' => true,
            'public'      => true,
            'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
            'taxonomies' => array('sector', 'subject', 'type'),
        )
    )
);

Я также создал таксономию type, которая назначается ресурсам:

register_taxonomy(  
    'type', 
    'type', 
    array(  
        'hierarchical' => true,  
        'label' => 'Type',  
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'type', 
            'with_front' => false 
        ) 
    )
); 

В бэкэнде WordPress все мои type:

enter image description here

Однако, когда я захожу в Внешний вид> Меню> и нажимаюв раскрывающемся списке «Категории» отображаются только следующие параметры:

enter image description here

Почему это так?

1 Ответ

0 голосов
/ 07 октября 2019

Здравствуйте. Пожалуйста, добавьте следующий код и проверьте, что вам не хватает многих вещей при создании resources типа записи. (Примечание: пожалуйста, удалите весь свой код, добавленный для создания resources поста и type таксономии)

function ro_resources_custom_post_type() {
    $labels = array(
        'name'                => __( 'Resources' ),
        'singular_name'       => __( 'Resource'),
        'menu_name'           => __( 'Resources'),
        'parent_item_colon'   => __( 'Parent Resource'),
        'all_items'           => __( 'All Resources'),
        'view_item'           => __( 'View Resource'),
        'add_new_item'        => __( 'Add New Resource'),
        'add_new'             => __( 'Add New'),
        'edit_item'           => __( 'Edit Resource'),
        'update_item'         => __( 'Update Resource'),
        'search_items'        => __( 'Search Resource'),
        'not_found'           => __( 'Not Found'),
        'not_found_in_trash'  => __( 'Not found in Trash')
    );
    $args = array(
        'label'               => __( 'resources'),
        'description'         => __( 'Best Resources'),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
        'public'              => true,
        'hierarchical'        => false,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'has_archive'         => true,
        'can_export'          => true,
        'exclude_from_search' => false,
            'yarpp_support'       => true,
        'publicly_queryable'  => true,
        'capability_type'     => 'page'
);
    register_post_type( 'resources', $args );
}
add_action( 'init', 'ro_resources_custom_post_type', 0 );

add_action( 'init', 'ro_create_resources_custom_taxonomy', 0 );

//create a custom taxonomy name it "type" for your posts
function ro_create_resources_custom_taxonomy() {

  $labels = array(
    'name' => _x( 'Types', 'taxonomy general name' ),
    'singular_name' => _x( 'Type', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Types' ),
    'all_items' => __( 'All Types' ),
    'parent_item' => __( 'Parent Type' ),
    'parent_item_colon' => __( 'Parent Type:' ),
    'edit_item' => __( 'Edit Type' ), 
    'update_item' => __( 'Update Type' ),
    'add_new_item' => __( 'Add New Type' ),
    'new_item_name' => __( 'New Type Name' ),
    'menu_name' => __( 'Types' ),
  );    

  register_taxonomy('types',array('resources'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'type' ),
  ));
}

Протестировано и хорошо работает

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...