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.

how to add datas in taxonomy to post with wp_insert_post this is my code but it is saved in my texonomy draft,why? i have given post_type=publish.

    $my_post = array(
        'post_title'    => 'test',
        'post_content'  => 'hello',
        'post_status'   => 'publish',
        'post_author'   => $userdata->ID,
        'post_type' => 'Newpostlist',

       );

      $post_id = wp_insert_post($my_post);
share|improve this question
    
post_category expects an array of term IDs, not a string/term slug –  Tom J Nowell Apr 4 '12 at 22:18
    
@TomJNowell Should be an answer. –  kaiser Apr 5 '12 at 4:34
add comment

1 Answer

post_category expects an array of term IDs, not a string/term slug

$news_term = get_term_by('name', 'news', 'category');
$term_id = $news_term->term_id;

Now use the terms ID not its slug/name in your query args.

'post_category' => array($term_id),
share|improve this answer
    
An example would probably be helpful. –  toscho Apr 5 '12 at 18:23
1  
I've added a generic example –  Tom J Nowell Apr 5 '12 at 18:31
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.