像这样的东西应该可以。代替wpse_77670_getPermittedCategories()
但是,您可以选择允许类别的数组,以及\'your_custom_category\'
无论您的自定义分类法适用于您的自定义帖子类型。
/**
* filter terms checklist args to restrict which categories a user can specify
* @param array $args arguments for function get_terms()
* @param array $taxonomies taxonomies to search
* @return array
*/
function wpse_77670_filterGetTermArgs($args, $taxonomies) {
// check whether we\'re currently filtering selected taxonomy
if (implode(\'\', $taxonomies) == \'your_custom_category\') {
$cats = wpse_77670_getPermittedCategories(); // as an array
if (empty($cats))
$args[\'include\'] = array(99999999); // no available categories
else
$args[\'include\'] = $cats;
}
return $args;
}
if (is_admin()) {
add_filter(\'get_terms_args\', \'wpse_77670_filterGetTermArgs\', 10, 2);
}
编辑,以在自定义帖子类型上使用常规“类别”分类法:
function wpse_77670_filterGetTermArgs($args, $taxonomies) {
global $typenow;
if ($typenow == \'tsv_userpost\') {
// check whether we\'re currently filtering selected taxonomy
if (implode(\'\', $taxonomies) == \'category\') {
$cats = array(89,90,91,92,93,94); // as an array
if (empty($cats))
$args[\'include\'] = array(99999999); // no available categories
else
$args[\'include\'] = $cats;
}
}
return $args;
}
if (is_admin()) {
add_filter(\'get_terms_args\', \'wpse_77670_filterGetTermArgs\', 10, 2);
}