0

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);
2
  • post_category expects an array of term IDs, not a string/term slug
    – Tom J Nowell
    Commented Apr 4, 2012 at 22:18
  • @TomJNowell Should be an answer.
    – kaiser
    Commented Apr 5, 2012 at 4:34

1 Answer 1

1

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),
2
  • An example would probably be helpful.
    – fuxia
    Commented Apr 5, 2012 at 18:23
  • 1
    I've added a generic example
    – Tom J Nowell
    Commented Apr 5, 2012 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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