I have a Dropdown Categories ..
<?php wp_dropdown_categories('taxonomy=faenas_combenef_category&hide_empty=0&orderby=name&order=asc&name=location') ?>
And my post Process... for tax
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
$title = trim($_POST['title']);
$content = trim($_POST['description']);
$location = trim($_POST['faenas_combenef_category']);
$my_post = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'faenas',
'tax_input' => array( $location )
);
$post_id = wp_insert_post($my_post);
wp_set_object_terms($post_id,$location,'faenas_combenef_category');
wp_redirect(home_url());
} // end IF
// Do the wp_insert_post action to insert it
do_action('wp_insert_post', 'wp_insert_post');
And my taxonomy register .....
$labels = array(
'name' => _x( 'Comunas de Beneficiarios', 'taxonomy general name' ),
'singular_name' => _x( 'Comuna de Beneficiario', 'taxonomy singular name' ),
'search_items' => __( 'Buscar Comuna de Beneficiario' ),
'all_items' => __( 'Comunas de Beneficiarios' ),
'parent_item' => __( 'Parent Product Category' ),
'parent_item_colon' => __( 'Parent Product Category:' ),
'edit_item' => __( 'Editar Comuna de Beneficiario' ),
'update_item' => __( 'Actualizar Comuna de Beneficiario' ),
'add_new_item' => __( 'Añadir Nueva Comuna de Beneficiario' ),
'new_item_name' => __( 'Nueva Comuna de Beneficiario' ),
'menu_name' => __( 'Comuna Beneficiario' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'combenef' ),
);
register_taxonomy( 'faenas_combenef_category', 'faenas', $args );
The post result OK but a "faenas_combenef_category" dont save in the custom post TAX please help, i dont know happend....
I change type of
My error was
$location = trim($_POST['faenas_combenef_category']);
i rewrite this by
$location = trim($_POST['location']);
But the post send value of Option and not the Name of Term of Taxonomy ....
My Post was
Title: Titledemo Description: Description Demo Location: 2
I need change this "2" by name of the Term of Taxonomy "faenas_combenef_category"
My print of dropdown categories is:
<select name="location" id="location" class="postform">
<option class="level-0" value="2">Canela</option>
<option class="level-0" value="5">Tambillos</option>
</select>
I need locate a solution please
SOLVED
I add function :
function custom_taxonomy_dropdown( $taxonomy ) {
$terms = get_terms( $taxonomy );
if ( $terms ) {
printf( '<select name="%s" class="postform">', esc_attr( $taxonomy ) );
foreach ( $terms as $term ) {
printf( '<option value="%s">%s</option>', esc_attr( $term->slug ), esc_html( $term->name ) );
}
print( '</select>' );
}
}
And change
$location = trim($_POST['faenas_combenef_category']);
And print my new dropdown
<p><?php custom_taxonomy_dropdown( 'faenas_combenef_category' ); ?></p>
Thanks Guys!