Answer the question
In order to leave comments, you need to log in
How to assign a taxonomy term to a post?
I have a bunch of records imported in the database with different custom post_types. At the same time, the theme creates an institution taxonomy like this
function my_taxonomies_institutions() {
$labels = array(
'name' => _x( 'Категории', 'taxonomy general name' ),
'singular_name' => _x( 'Категория', 'taxonomy singular name' ),
'search_items' => __( 'Найти' ),
'all_items' => __( 'Все' ),
'parent_item' => __( 'Родительская' ),
'parent_item_colon' => __( 'Родительская:' ),
'edit_item' => __( 'Редактировать' ),
'update_item' => __( 'Обновить' ),
'add_new_item' => __( 'Добавить новую' ),
'new_item_name' => __( 'Новая' ),
'menu_name' => __( 'Категории' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'show_admin_column' => true,
'rewrite' => array( 'hierarchical' => true, 'slug' => 'institutions' ),
);
register_taxonomy( 'institutions', 'institution', $args );
}
add_action( 'init', 'my_taxonomies_institutions', 0 );
print term_exists('sekcii'); // 7
$ret = wp_set_post_terms($pid, 7, 'institution');
$ret = wp_set_post_terms($pid, 'sekcii', 'institution');
$ret = wp_set_post_terms($pid, 7, 'Категория');
$ret = wp_set_post_terms($pid, 'Секции', 'Категория');
WP_Error Object ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy. ) ) [error_data] => Array ( ) )
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question