A
A
Alex2018-05-21 06:38:23
WordPress
Alex, 2018-05-21 06:38:23

Why is a new element created in the taxonomy when publishing a post in wordpress?

Created 2 types of post "Commercial premises" and "Slides".

function  register_post_type_appartment() {
    register_post_type( 'appartment',        
        array(
            'labels' => array(
                'name'  => 'Коммерческие помещения',
                'singular_name' => 'Объект',
                'menu_name'  => 'Коммерческие помещения',
                'name_admin_bar' => 'Объект',
                'add_new'  => 'Новый объект',
                'add_new_item' => 'Добавить новый объект',
                'new_item' => 'Новый объект',
                'edit_item' => 'Редактировать объект',
                'view_item' => 'Просмотреть объект',
                'all_items' => 'Все помещения',
                'search_items'  => 'Найти объект',
                'not_found' => 'Помещения не найдены.',
                'not_found_in_trash' => 'No found in Trash.'
            ),
            'public' => false,
            'show_ui' => true,
            'has_archive'	=> false,
            'hierarchical' => true,
            'menu_icon' => 'dashicons-admin-home',
            'capability_type' => 'post',			
            'menu_position' => 5,
            'supports' => array( 'title', 'revisions',  ) 
        )
    ); 
}

add_action( 'init', 'register_post_type_appartment' );

function  register_post_type_slides() {
    register_post_type( 'slides',        
        array(
            'labels' => array(
            'name'  => 'Слайды',
            'singular_name' => 'Слайд',
            'menu_name'  => 'Слайды',
            'name_admin_bar' => 'Слайд',
            'add_new'  => 'Новый слайд',
            'add_new_item' => 'Добавить новый слайд',
            'new_item' => 'Новый слайд',
            'edit_item' => 'Редактировать слайд',
            'view_item' => 'Просмотреть слайд',
            'all_items' => 'Все слайды',
            'search_items'  => 'Найти слайд',
            'not_found' => 'Слайды не найдены.',
            'not_found_in_trash' => 'No found in Trash.'
            ),
            'public' => false,
            'show_ui' => true,
            'has_archive'	=> false,
            'hierarchical' => true,
            'menu_icon' => 'dashicons-images-alt',
            'capability_type' => 'post',			
            'menu_position' => 6,
            'supports' => array( 'title', 'revisions', 'editor', 'thumbnail',  ) 
        )
    ); 
}
add_action( 'init', 'register_post_type_slides' );

These two types of posts have a common taxonomy "LCD" I create it like this
function register_taxonomy_complex() {
    register_taxonomy('complex', array('appartment', 'slides'), array(
        'label' => '',
        'labels' => array(
        'name' => 'Жилые комплексы',
        'singular_name' => 'Жилой комплекс',
        'search_items' => 'Найти ЖК',
        'all_items' => 'Все ЖК',
        'view_item ' => 'Посмотреть ЖК',
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => 'Редактировать ЖК',
        'update_item' => 'Обновить ЖК',
        'add_new_item' => 'Добавить ЖК',
        'new_item_name' => 'Новый ЖК',

        'menu_name' => 'Жилые комплексы',
        ),
        'description'           => '',
        'public'                => true,
        'show_in_menu'          => true,
        'show_tagcloud'         => true,
        'show_in_rest'          => null,
        'rest_base'             => null,
        'hierarchical'          => false,
        'update_count_callback' => '',
        'rewrite'               => true,
        'capabilities'          => array(),
        'meta_box_cb'           => 'post_categories_meta_box',
        'show_admin_column'     => false,
        '_builtin'              => false,
        'show_in_quick_edit'    => null,
    ));
}

add_action( 'init', 'register_taxonomy_complex' );

I created a taxonomy in the admin panel, then I create either a slide or a room, put a tick on the desired LCD and when publishing, a new element is created in the taxonomy with a name number and a label number and the post is automatically assigned to it. If you go to the list of all objects in a specific post type and set the taxonomy for the post through the properties and update, then everything is fine. What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question