How can a category be assigned to a new front-end post submission?
Posting works, Category is not assigned.
Would like to be able to add more than one, if possible.
Both are CPT and custom taxonomies.
if ( isset( $_POST['submitted'] ) && isset( $_POST['new_post_nonce_field'] ) && wp_verify_nonce( $_POST['new_post_nonce_field'], 'new_post_nonce_action' ) ) {
$new_post = array(
'post_content' => $_POST['post-content'],
'post_title' => wp_strip_all_tags( $_POST['post-title'] ),
'post_type' => 'custom_pt',
'post_category' => array(
'custom_tax' => $_POST['custom_tax']
),
);
if ( !$hasError == true ) {
$post_id = wp_insert_post( $new_post );
if ( post_id ) {
wp_redirect( home_url() );
}
}
}
.
<form id="new_post" method="POST" action="" enctype="multipart/form-data">
<label for="post-title">The Title</label>
<input id="post-title" name="post-title" type="text" />
<label for="post-content">The Content</label>
<textarea id="post-content" name="post-content"></textarea>
<label for="custom_tax">The Categories</label>
<?php wp_dropdown_categories( 'tab_index=10&taxonomy=custom_tax&name=custom_tax&class=custom_tax&show_option_all=Select a category' ); ?>
<?php wp_nonce_field( 'new_post_nonce_action', 'new_post_nonce_field' ); ?>
<button type="submit">Publish</button>
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
Thank You.