Set a custom category in a custom post
-
Hi everybody,
I have a custom post “artist” and a taxonomy/category “artist category”, and i want to create (by development) a new post and set the category of the artist but it doesn’t work.
i have testing with this
function createNewPost( $response ){ global $userMeta; $userID = $response->ID; $user = new WP_User( $userID ); $role = $userMeta->getUserRole(); //$catId = get_cat_ID("dj"); if( $role = 'artiste' ){ // Assume you have custom role named 'artist' $newPost = array( 'post_title' => $user->nickname, // You can use user data here, for first_name: $user->first_name 'post_content' => $user->description, 'post_status' => 'pending', 'post_author' => $userID, 'post_type' => 'cpt_artists', // Assume, you have a custom post type named 'artist' 'tax_input' => array('artist-category' => array('dj') )); $post_id = wp_insert_post( $newPost ); wp_set_post_terms( $post_id, array( 'dj'), 'artist-category'); } }
But no working too.
For test i have listed all the taxonomy of wordpress and the result is :
category
post_tag
nav_menu
link_category
post_formatWhy my custom taxonomy “artist-category” is not listed here ??
Thanks to all
- The topic ‘Set a custom category in a custom post’ is closed to new replies.