我试图通过选择复选框来保存自定义分类法。通常,如果是selectbox,则没有问题。但当我使用复选框选择术语时,它不会保存。我怀疑这是阵列问题,但我无法解决。我请求你的帮助。对不起,我的英语不好。非常感谢。
下面是添加帖子的部分`
// 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.
);
`
这是拯救岗位,
//SAVE THE POST
$pid = wp_insert_post($new_post, $wperror);
wp_set_post_terms($pid,array($_POST[\'genre\']),\'genre\',true);
下面的代码用于我的自定义分类,流派将类似于音乐类型`
<?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;
}
?>
`