почему не меняется категория поста при сохранении с фротенда?

хотя в масиве ,она поменялась

add_action( 'save_post', 'set_sandbox' );
function set_sandbox( $post_id ){
        $category = get_the_category($post_id);
        $category_item = $category[0]->cat_ID;
        // Удаляем хук, чтобы не было зацикливания
        remove_action( 'save_post', 'set_sandbox' );
        add_metadata( 'post', $post_id, 'post_category_old', $category_item, true );
        // обновляем запись. В это время срабатывает событие save_post
        print_r($category);
        wp_set_post_categories( $post_id, 27, false );
         $category2 = get_the_category($post_id);
        print_r($category2);
        // Ставим хук обратно
        add_action( 'save_post', 'set_sandbox' );
 
    
}


Array
(
    [0] => WP_Term Object
        (
            [term_id] => 1
            [name] => Без рубрики
            [slug] => bez_rubriki
            [term_group] => 0
            [term_taxonomy_id] => 1
            [taxonomy] => category
            [description] => 
            [parent] => 0
            [count] => 34
            [filter] => raw
            [cat_ID] => 1
            [category_count] => 34
            [category_description] => 
            [cat_name] => Без рубрики
            [category_nicename] => bez_rubriki
            [category_parent] => 0
        )

)
Array
(
    [0] => WP_Term Object
        (
            [term_id] => 27
            [name] => Песочница
            [slug] => sandbox
            [term_group] => 0
            [term_taxonomy_id] => 27
            [taxonomy] => category
            [description] => 
            [parent] => 11
            [count] => 24
            [filter] => raw
            [cat_ID] => 27
            [category_count] => 24
            [category_description] => 
            [cat_name] => Песочница
            [category_nicename] => sandbox
            [category_parent] => 11
        )

)
Array
(
)
Array
(
    [0] => WP_Term Object
        (
            [term_id] => 27
            [name] => Песочница
            [slug] => sandbox
            [term_group] => 0
            [term_taxonomy_id] => 27
            [taxonomy] => category
            [description] => 
            [parent] => 11
            [count] => 24
            [filter] => raw
            [cat_ID] => 27
            [category_count] => 24
            [category_description] => 
            [cat_name] => Песочница
            [category_nicename] => sandbox
            [category_parent] => 11
        )

)
Array
(
    [0] => WP_Term Object
        (
            [term_id] => 27
            [name] => Песочница
            [slug] => sandbox
            [term_group] => 0
            [term_taxonomy_id] => 27
            [taxonomy] => category
            [description] => 
            [parent] => 11
            [count] => 24
            [filter] => raw
            [cat_ID] => 27
            [category_count] => 24
            [category_description] => 
            [cat_name] => Песочница
            [category_nicename] => sandbox
            [category_parent] => 11
        )

)
Array
(
    [0] => WP_Term Object
        (
            [term_id] => 27
            [name] => Песочница
            [slug] => sandbox
            [term_group] => 0
            [term_taxonomy_id] => 27
            [taxonomy] => category
            [description] => 
            [parent] => 11
            [count] => 24
            [filter] => raw
            [cat_ID] => 27
            [category_count] => 24
            [category_description] => 
            [cat_name] => Песочница
            [category_nicename] => sandbox
            [category_parent] => 11
        )

)

Ответы (0 шт):