0

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!

  • Can you just do print_r($location); and tell me what is the output? – Vinod Dalvi Sep 8 '13 at 7:59
1

I think you have used wrong tax_input parameter value for wp_insert_post() function it should be array like this

array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) )  

as shown in the following code

$my_post = array(
        'post_title'    => $title,
        'post_content'  => $content,
        'post_status'   => 'publish',
        'post_type' => 'faenas',
        'tax_input'    => array( 'faenas_combenef_category' => array( $location ) )
);
  • +1 from me, tax_input accept array of taxonomy terms, which asker was ignored. – Anjum Sep 8 '13 at 8:48
  • respective changes made ​​and still the same problem – Cristian Recabarren Sep 8 '13 at 21:46
  • This is my print of my dropdown categories <select name="location" id="location" class="postform"> <option class="level-0" value="2">Canela</option> <option class="level-0" value="5">Tambillos</option> </select> – Cristian Recabarren Sep 8 '13 at 22:18
0

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.