I’ve created a plugin that auto creates a post and attaches a category to it, which is then hidden from the main blog and only shows in the category listing…
I can successfully add a new post via wp_insert_post with all the correct params and once the post_id is returned I’m calling wp_set_object_terms with the category I want that post to be included under.
I can confirm that the post is created, and the post has the correct category. However, if I visit the category listing for that particular cat, I see all the previous posts but not the dynamically created one. If I manually add a new post and select the same category, it does display in the list.
I haven’t found anything regarding why this is happening… Has anyone else run into this issue? Everything seems to be working fine, except with the category listing…
(Edited to add code sample)
$new_post = array(
'post_title' => $postTitle,
'post_content' => '$postContent,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $current_user->ID,
'post_type' => 'post'
);
$post_id = wp_insert_post($new_post);
wp_set_object_terms($post_id, array(24), 'category');