我一直尝试这样做,不幸的是,在类别为空的情况下,我发现只有商店(前端)的解决方案等等。
我基本上想要做的是,当我在Prodct Categories部分创建新产品时
我想显示/隐藏某些类别。
到目前为止,我还没有找到任何相关内容,任何想法如何才能完成?
感谢。
答案 0 :(得分:2)
尝试以下代码:
function is_edit_page($new_edit = null){
global $pagenow;
//make sure we are on the backend
if (!is_admin()) return false;
if($new_edit == "edit")
return in_array( $pagenow, array( 'post.php', ) );
elseif($new_edit == "new") //check for new post page
return in_array( $pagenow, array( 'post-new.php' ) );
else //check for either new or edit
return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
}
function so_28055266_filterGetTermArgs($args, $taxonomies) {
global $typenow;
if ($typenow == 'product') {
// check whether we're currently filtering selected taxonomy
if (implode('', $taxonomies) == 'product_cat' && is_edit_page()) {
//Add categories term ID that you want to show
$cats = array(9,10,11,12); // List of category(term ID) that you want to add as an array
if (empty($cats))
$args['include'] = array(99999999); // no available categories
else
$args['include'] = $cats; //It will only show the category that you mentioned in above array
}
}
return $args;
}
if (is_admin()) {
add_filter('get_terms_args', 'so_28055266_filterGetTermArgs', 10, 2);
}
让我知道输出。