【发布时间】:2021-07-23 14:20:23
【问题描述】:
我正在使用 WC 供应商,并根据他们的建议使用 wp_term_checklist 在产品上输出名为“位置”的分类法。我已经将它保存到产品中,但它没有保存前端的复选框选择。 这是我添加到 product-edit.php 模板中的代码
$args = array(
'descendants_and_self' => 0,
'selected_cats' => false,
'popular_cats' => false,
'walker' => null,
'taxonomy' => 'location',
'checked_ontop' => false
);
wp_terms_checklist( $my_postid, $args );
$post_to_edit = array(
'ID' => $my_postid,
'tax_input' => array( 'location' => array($_POST['tax_input']['location']) )
);
$pid = wp_update_post($post_to_edit);
if ( isset($_POST['tax_input']['location']) && is_array( $_POST['tax_input']['location'] ) ) {
$location = array_map( 'intval', $_POST['tax_input']['location'] );
$location = array_unique( $location );
wp_set_post_terms($pid, $location, 'location');
}
这是他们使用多选的代码,但我们需要复选框: https://gist.github.com/digitalchild/128033d2d41f682acd4387b595d4f607
【问题讨论】:
标签: wordpress taxonomy wcvendors