问题描述
我正在尝试在类别上添加复选框选项,但是我的代码无法正常工作 好像有些错误,您可以通过保存表单让我知道实际的代码吗? 我可以在我的function.php中使用该代码
我的分类名称是产品类别,帖子类型是产品
所以我需要添加复选框或单选按钮 像这样(https://prnt.sc/uvonej)
这是我正在使用的代码
function products_taxonomy_custom_fields($tag) {
// Check for existing taxonomy meta for the term you're editing
$t_id = $tag->term_id; // Get the ID of the term you're editing
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
?>
<tr class="form-field">
<th scope="row" valign="top">
<label for="products_id"><?php _e('Main box'); ?></label>
</th>
<td>
<input type="checbox" name="term_meta[products_id]" id="term_meta[products_id]" size="25" style="width:60%;" value="<?php echo $term_meta['products_id'] ? $term_meta['products_id'] : ''; ?>"><br />
</td>
</tr>
<?php
}
// A callback function to save our extra taxonomy field(s)
function save_taxonomy_custom_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_term_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ){
if ( isset( $_POST['term_meta'][$key] ) ){
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
//save the option array
update_option( "taxonomy_term_$t_id",$term_meta );
}
}
这是我的毒物学名称(由CPT代码创建) https://prnt.sc/uvopcj
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)