This is my issue, i hope to find the answer here.
<div class="form-group">
<label for="genres" class="col-sm-2 control-label">genres</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="genres" name="genres">
</div>
</div>
// Genres value is : anime, action, adventure,
function post_creation() {
if(isset($_POST['movie_nonce_field']) && wp_verify_nonce($_POST['movie_nonce_field'], 'movie_nonce')) {
if(strlen(trim($_POST['title'])) < 1 || strlen(trim($_POST['overview'])) < 1) {
$redirect = add_query_arg('post', 'failed', home_url($_POST['_wp_http_referer']));
} else {
$category = array( $_POST['genres'] );
$post_info = array(
'post_type' => 'movies',
'post_status' => 'pending',
'post_title' => esc_attr(strip_tags($_POST['title'])),
'post_content' => esc_attr(strip_tags($_POST['overview'])),
'post_category' => $category,
);
$post_id = wp_insert_post($post_info);
if($post_id) {
update_post_meta($post_id, 'ecpt_postedby', esc_attr(strip_tags($_POST['user_name'])));
update_post_meta($post_id, 'ecpt_posteremail', esc_attr(strip_tags($_POST['user_email'])));
update_post_meta($post_id, 'ecpt_contactemail', esc_attr(strip_tags($_POST['inquiry_email'])));
$redirect = add_query_arg('post', 'successfull', home_url($_POST['_wp_http_referer']));
}
}
wp_redirect($redirect); exit;
}
}
add_action('init', 'post_creation');
Categories not save to post.
I want to add new post to categories if it already exist And create new category if it doesn't exist