我有一个下拉列表类别。。
<?php wp_dropdown_categories(\'taxonomy=faenas_combenef_category&hide_empty=0&orderby=name&order=asc&name=location\') ?>
和我的后期处理。。。用于税务
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\');
和我的分类登记册。。。。。
$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 );
发布结果正常,但“faenas\\u combenef\\u类别”不保存在自定义的税后请帮助,我不知道发生了什么。。。。
I更改类型
我的错误是
$location = trim($_POST[\'faenas_combenef_category\']);
我重写了这个
$location = trim($_POST[\'location\']);
但选项的post-send值,而不是分类术语的名称。。。。
我的帖子是
标题:Titledemo描述:描述演示位置:2
我需要将这个“2”改为分类学术语“faenas\\u combenef\\u category”
我打印的下拉类别是:
<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添加功能:
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>\' );
}
}
和更改
$location = trim($_POST[\'faenas_combenef_category\']);
并打印我的新下拉列表
<p><?php custom_taxonomy_dropdown( \'faenas_combenef_category\' ); ?></p>
谢谢大家!