Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
share|improve this question
2  
do you set post_status? it would help to see the code that inserts the post. –  Milo Feb 18 '13 at 0:33
    
code sample added... the post shows up in the post listing with the category added which tells me everything I did was correct. –  orderofout Feb 18 '13 at 19:34
    
what does it say in the date column in the admin post list? is it Published, or possibly Scheduled? –  Milo Feb 18 '13 at 19:53
    
I've experienced this too when programatically creating posts. For some reason the category/term count are not updated. I think the same goes for imports as well. See this thread for a possible explanation and solution. –  Simon Feb 18 '13 at 20:28
    
@milo you hit the nail on the head. It is scheduled for 4 hours from now. Well at least now I know what's causing the issue. If only I could give you credit for pointing that out. Thanks! –  orderofout Feb 19 '13 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.