L
L
LastGeneral2021-07-27 12:39:36
WordPress
LastGeneral, 2021-07-27 12:39:36

How to add a category to the created post type?

I made my own post type, how to add categories like "grill" and "brazier" to it

// Add Post Type Recipes
function super_grill_recipes() {
    $labels = array(
        'name' => _x( 'Рецепты', 'Тип записей Рецепты', 'root' ),
        'singular_name' => _x( 'Рецепты', 'Тип записей Рецепты', 'root' ),
        'menu_name' => __( 'Рецепты', 'root' ),
        'all_items' => __( 'Все рецепты', 'root' ),
        'view_item' => __( 'Смотреть рецепт', 'root' ),
        'add_new_item' => __( 'Добавить новый рецепт', 'root' ),
        'add_new' => __( 'Добавить новый', 'root' ),
        'edit_item' => __( 'Редактировать рецепт', 'root' ),
        'update_item' => __( 'Обновить рецепты', 'root' ),
        'search_items' => __( 'Искать рецепт', 'root' ),
        'not_found' => __( 'Не найдено', 'root' ),
        'not_found_in_trash' => __( 'Не найдено в корзине', 'root' ),
    );

    $args = array(
        'label' => __( 'recipes', 'root' ),
        'description' => __( 'Каталог рецептов', 'root' ),
        'labels' => $labels,
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'taxonomies' => array( 'genres' ),
        'hierarchical' => false,
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 5,
        'can_export' => true,
        'has_archive' => true,
        'exclude_from_search' => false,
        'publicly_queryable' => true,
        'capability_type' => 'page',
    );

    register_post_type( 'recipes', $args );
}
add_action( 'init', 'super_grill_recipes' );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yarovikov, 2021-07-27
@LastGeneral

register_taxonomy(
    'mangal',
    array('recipes'),
    array(
      'hierarchical' => true,
      'show_admin_column' => true,			
      'show_in_rest' => true,
      'publicly_queryable' => true,
    )
  );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question