我正在尝试从new post屏幕上的category小部件(默认)中排除一个术语(id=46),但我无法获取其id,因此我可以取消设置或删除它
add_action( \'load-post-new.php\', \'add_filter_cat_category\' );
add_action( \'load-post.php\', \'add_filter_cat_category\' );
function add_filter_cat_category()
{
global $typenow;
if( \'blogs\' != $typenow )
return;
add_filter( \'the_category\', \'filter_cat_category\' );
}
function filter_cat_category( $cat_name )
{
$cat_id = get_cat_ID( $cat_name );
$category = get_category( $cat_id );
$count = $category->category_count;
return "$cat_name($count)";
}
谁能帮帮我!
最后,我找到了一个解决方案,
这不是一项义务工作,但它正在发挥作用
add_action( \'load-post-new.php\', \'add_filter_cat_category\' );
add_action( \'load-post.php\', \'add_filter_cat_category\' );
function add_filter_cat_category()
{
global $typenow;
if( \'blogs\' != $typenow )
return;
add_filter( \'the_category\', \'filter_cat_category\' );
add_filter( \'list_terms_exclusions\', \'custome_list_terms_exclusions\', 10, 2 );
}
// change the name of the exclusions term
function filter_cat_category( $cat_name )
{
if ( $cat_name == \'old_name\' ) {
$cat_name .= \'_extra name\'; // this is new name
}
return "$cat_name";
}
// hide exclusion ids
function custome_list_terms_exclusions( $exclusions, $args ) {
// IDs of terms to be excluded
$exclude = "46,48";
$exterms = wp_parse_id_list( $exclude );
foreach ( $exterms as $exterm ) {
if ( empty( $exclusions ) )
$exclusions = \' AND ( t.term_id <> \' . intval( $exterm ) . \' \';
else
$exclusions .= \' AND t.term_id <> \' . intval( $exterm ) . \' \';
}
if ( !empty( $exclusions ) )
$exclusions .= \')\';
return $exclusions;
}
你的想法对我的未来很有价值