I am trying to save custom taxonomies by choosing checkboxes. Normally if it is selectbox, there is no problem. But when I use checkboxes to choose terms it doesn't save. I am suspected that it is an array problem but I could not solve. I request your very kind help. Sorry my bad English. Thank you.
Here is the part to add the post; `
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title' => $title,
'post_category' => array($_POST['cat']), // Usable for custom taxonomies too
'post_status' => 'publish', // Choose: publish, preview, future, draft, etc.
'post_type' => 'post', //'post',page' or use a custom post type if you want to
'tax_input' => array( 'genre' => array($_POST['genre']) ) // support for custom taxonomies.
);
`
And This is saving the post,
//SAVE THE POST
$pid = wp_insert_post($new_post, $wperror);
wp_set_post_terms($pid,array($_POST['genre']),'genre',true);
The code below is for my custom taxonomy, genre will be something like music type. `
<?php
$genres = get_terms('genre', 'orderby=id&hide_empty=0');
$counter = 0;
foreach ($genres as $genre) {
$counter++;
$option = '<input type="checkbox" name="genre[]" id="'.$genre->name.'" value="'.$genre->name.'">';
$option .= '<label for="genre">'.$genre->name.'</label>';
echo $option;
}
?>
`
print_r(array($_POST['genre']));
I got this;Array ( [0] => Array ( [0] => Term1 [1] => Term2 [2] => Term3 ) )
– Baysolucan Oct 3 '11 at 5:54