0

введите сюда описание изображения

Вот код создания постайпа и таксономии:

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

function register_post_news() {
$args = array(
    'labels' => array(
        'name' => _x( 'Cars', 'Post Type General Name', 'text_domain' ),
        'all_items' => __( 'All Cars' ),
          ),

    'description' => '',
    'public' => true,
    'exclude_from_search' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_nav_menus' => true,
    'show_in_menu' => true,
    'show_in_admin_bar' => true,
    'menu_position' => 20,
    'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
    'map_meta_cap' => null,
    'hierarchical' => false,
    // Управление полями для редактирования объекта типа записи.
    'supports' => array(
        'title',
        'editor',
        'author',
        'thumbnail',
        'excerpt',
        'trackbacks',
        'custom-fields',
        'comments',
        'revisions',
        'page-attributes',
        'post-formats',
    ),
    'register_meta_box_cb' => null,
    'taxonomies' => array('taxnews'),
    'has_archive' => false,
    'rewrite' => array(
        'slug' => 'news',
        'with_front' => false,
        'feeds' => false,
        'pages' => true,
    ),
    'permalink_epmask' => EP_PERMALINK,
    'query_var' => true,
    'can_export' => true,
    'delete_with_user' => null,
    'show_in_rest' => false,
    'rest_base' => $post_type,
    '_builtin' => false,
    );
register_post_type( 'news', $args );
}

add_action( 'init', 'create_taxnews', 0 );
function create_taxnews() {
$args = array(
/*
  'show_admin_column' => true, 
*/
    'label' => _x( 'Models', 'taxonomy general name' ),
    'labels' => array(
        'name' => _x( 'Models', 'taxonomy general name' ),
        'singular_name' => _x( 'Model', 'taxonomy singular name' ),
        'menu_name' => __( 'Models' ),
        ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'show_tagcloud' => true,
    'show_in_quick_edit' => true,
    'meta_box_cb' => null,
    'show_admin_column' => false,
    'description' => '',
    'hierarchical' => true,
    'update_count_callback' => '',
    'query_var' => true,
    'rewrite' => array(
        'slug' => 'taxnews',
        'with_front' => false,
        'hierarchical' => true,
        'ep_mask' => EP_NONE,
    ),

    'sort' => null,
    '_builtin' => false, );
register_taxonomy( 'taxnews', array('news'), $args );
}

2 ответа 2

2

В массив $args при регистрации таксономии добавьте один элемент:

'show_admin_column' => true,
0
1
add_filter( 'manage_news_posts_columns', 'set_custom_edit_news_columns' );
add_action( 'manage_news_posts_custom_column' , 'custom_news_column' );

function set_custom_edit_news_columns($columns) {
    $columns['taxnews'] = __( 'Models', 'your_text_domain' );
    return $columns;
}

function custom_news_column( $column, $post_id ) {
    if ( $column == 'taxnews' ){
            echo  get_the_term_list( $post_id , 'taxnews' , '' , ',' , '' );
    }
}

https://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.