Reputation: 654
I can create a new category using wp_insert_category but I can not add it to my post, any suggestion please!
$cat = array(
'cat_name' => 'dossiers-a-suivre',
'cat_slug' => 'dossiers-a-suivre',
'taxonomy' => 'category' );
$cat_id = wp_insert_category( $cat );
$my_post = array(
'post_title' => "post test",
'post_content' => 'This is my post.',
'post_date' => date('Y-m-d H:i:s'),
'post_type' => 'folder',
'post_category' => array( $cat_id)
);
$post_id = $this->insert_post($my_post);
Upvotes: 0
Views: 1149
Reputation: 654
I solved the problem by using wp_set_object_terms :)
$cat = array(
'cat_name' => 'dossiers-a-suivre',
'cat_slug' => 'dossiers-a-suivre',
'taxonomy' => 'category' );
$cat_id = wp_insert_category( $cat );
$my_post = array(
'post_title' => "post test",
'post_content' => 'This is my post.',
'post_date' => date('Y-m-d H:i:s'),
'post_type' => 'folder',
'category_name' => 'dossiers-a-suivre',
);
$post_id = $this->insert_post($my_post);
wp_set_object_terms($post_id, $cat_id, 'category' );
Upvotes: 3