I have a custom post type name session and a tag name post_tag.
This is the declaration of my custom post type :
function create_posttype()
{
register_post_type(
'session',
array(
'labels' => array(
'name' => __('Sessions'),
'singular_name' => __('Session'),
'menu_name' => __('Sessions'),
'all_items' => __('Toutes les sessions'),
'view_item' => __('Voir sessions'),
'add_new' => __('Ajouter'),
'edit_item' => __('Modifier'),
),
'hierarchical' => true,
'public' => true,
'show_in_rest' => true,
'supports' => array('title', 'thumbnail', 'revisions, custom-fields'),
'taxonomies' => array('category', 'post_tag'),
'menu_position' => 20,
'menu_icon' => 'dashicons-groups',
)
);
}
add_action('init', 'create_posttype');
I need to add a tag, so i do this :
wp_set_post_tags($session->ID, "annule", false);
It works. But then i have a problem with my total of post type for this tags in the backend. So i do this :
$update_taxonomy = 'post_tag';
$get_terms_args = array('taxonomy' => $update_taxonomy,'hide_empty' => false);
$update_terms = get_terms($get_terms_args);
wp_update_term_count_now($update_terms, $update_taxonomy);
But this doesn’t work.
I suppose i’m doing something wrong. But i don’t see what ?
Thanks