Assign category to front end post

I checked and it works with this:

$new_post = array(
    'post_content'  =>  $_POST['post-content'],
    'post_title'    =>  wp_strip_all_tags( $_POST['post-title'] ),
    'post_type'     => 'custom_pt'
);

note: I used a text input for the single category

<input id="input-name-value" name="input-name-value" type="text" />

I havent tried it with a select – option dropdown. or more than 1 category.

$post_id = wp_insert_post( $new_post );

wp_set_object_terms( $post_id, $_POST['input-name-value'], 'yourCategory' );

It would be nice if someone could pimp this out in order to get full functionallity.

Thanks.

Leave a Comment