First, you should change your input field names to something unique. category
is a WordPress query var, so submitting a form with that field name may have unexpected results.
That said, post_category
is only for the category
taxonomy, custom taxonomies should use the tax_input
parameter.
however… if this form is being submitted by users who are not logged in or don’t have the capability to assign terms in your custom taxonomy, then you must use wp_set_object_terms
to assign terms after the post is inserted. See the note in wp_insert_post
:
‘tax_input’: Equivalent to calling wp_set_post_terms() for each custom taxonomy in the array. If the current user doesn’t have the capability to work a taxonomy, the you must use wp_set_object_terms() instead.
EDIT-
for the select field, you can output the term ID as the option value:
<?php
// ======= Custom post types category drop down ========
$taxonomy = 'walls';
$terms = get_terms($taxonomy); // Get all terms of a taxonomy
if ( $terms && !is_wp_error( $terms ) ) :
foreach ( $terms as $term ) {
echo '<option value="' . $term->term_id . '">' . $term->name . '</option>';
}
endif;
?>
Then when you insert the post:
'tax_input' => array( 'walls' => array( $_POST['your_tax_field'] ) )