Z
Z
zzmaster2019-02-21 23:04:44
Taxonomy
zzmaster, 2019-02-21 23:04:44

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 );

In the admin panel there is a menu item Institutions and inside - Categories. For example, the category Sections (sekcii).
Now, in order for the topic designed for these taxonomies to work, I need to go through the database and if in the post_type=sekcii set it (as I understand it) the term sekcii of the institution taxonomy. It seems that this is done by the wp_set_post_terms
function First, I determine the id of the term: then I try these options
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, 'Секции', 'Категория');

every time i get
WP_Error Object ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy. ) ) [error_data] => Array ( ) )

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zzmaster, 2019-02-23
@zzmaster

I was prompted here that I should use institution s and not units. number. The question is closed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question