I setup a custom content type known as "photo" that is working fine. Now I am placing posts with this content type using wordpress_place_publish() and am experiencing an issue adding a category. They are hierarchical groups which i connected using the publish type and may occur the admin area, however i attempt to connect them using PHP code, it does not work.
This is actually the code snippet:
$new_entry = array(); $new_entry['post_title'] = $_POST['submit-title']; $new_entry['post_content'] = ''; $new_entry['post_status'] = 'pending'; $new_entry['post_type'] = 'photo'; $new_entry['post_author'] = $userID; $new_entry['post_category'] = array(6,7); // this is the line that doesn't work $new_entry['tags_input'] = array('nature','people','fun'); // this also doesn't work // Insert the post into the database $post_id = wp_insert_post( $new_entry );
All of this works and also the custom publish is placed and turns up not surprisingly, however it does not have groups designated into it. (Groups 6 and 7 are groups that needs to be connected using the "photo" publish type). In addition to that the tags will also be not produced and connected with this particular publish.
Does anybody have ideas on which I am doing wrong or any other approaches they recommend?
There's a function for your, it's known as wordpress_set_object_terms(). http://codex.wordpress.org/Function_Reference/wp_set_object_terms
wp_set_object_terms( $post_id, $category_ids, 'category');
you should use exactly the same function to include tags