在网上搜索了很多之后,我找到了一个解决方案,您可以将想要隐藏的类别的ID作为数组传入,然后将其粘贴到函数中。php文件。将为管理员显示所有类别
$exclude\\u array=数组(“5”、“6”、“7”、“1”);
function hide_categories_for_specific_user( $exclusions, $args ){
if (!current_user_can(\'manage_options\') ) {
// IDs of terms to be excluded
$exclude_array = array("5","6","7","1"); // CHANGE THIS TO IDs OF YOUR TERMS
// Generation of exclusion SQL code
$exterms = wp_parse_id_list( $exclude_array );
foreach ( $exterms as $exterm ) {
if ( empty($exclusions) )
$exclusions = \' AND ( t.term_id <> \' . intval($exterm) . \' \';
else
$exclusions .= \' AND t.term_id <> \' . intval($exterm) . \' \';
}
// Closing bracket
if ( !empty($exclusions) )
$exclusions .= \')\';
// Return our SQL statement
return $exclusions;
}
}
// Finally hook up our filter
add_filter( \'list_terms_exclusions\', \'hide_categories_for_specific_user\', 10, 2 );