0

I have a form to create new post and I pass my post_category into post creating array, but it not insert into that category , it insert into Uncategorized category.And I want to see the post using the menu that I created using categories.

I pass may data to following array to create post.Its working but it insert post into Uncategorized(default) category. any solution?

 $post = array('post_type'=>'post',
              'post_author'=>$author,
              'post_status'=>'publish',
              'post_title'  => 'Test Title',
              'post_category' => '679'
            );

2 Answers 2

1

The post_category parameter has to be an array, try this:

$post = array('post_type'=>'post',
 'post_author'=>$author,
 'post_status'=>'publish',
 'post_title'  => 'Test Title',
 'post_category' => array('679')
);

Ref: http://codex.wordpress.org/Function_Reference/wp_insert_post#Parameters

If that doesn't work for you, try using category_name:

'category_name' => 'category_name',
2
  • unfortunately I have Sub categories with same name under different main categories Commented Apr 17, 2017 at 11:54
  • OK, but did adding the category ID as an array work? Commented Apr 17, 2017 at 13:43
0

Issue is in following line

'post_category' => array('679')

Use 'post_category' => array(679) without single quote.

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.