谁能给我一个函数或一个方法的想法,我需要使用它从wp admin的选择框中隐藏类别?
我有一个自定义的帖子类型,我希望我的作者在编辑帖子时只能在其中的5个类别中进行选择。我想这只是与自定义职位类型的情况,而不是常规职位。
谁能给我一个函数或一个方法的想法,我需要使用它从wp admin的选择框中隐藏类别?
我有一个自定义的帖子类型,我希望我的作者在编辑帖子时只能在其中的5个类别中进行选择。我想这只是与自定义职位类型的情况,而不是常规职位。
像这样的东西应该可以。代替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);
}
我正在使用get_the_term_list 和manage_posts_custom_column 在WordPress Admin中,在自定义帖子列表中显示自定义分类法的术语。add_action( \'manage_mycustompost_posts_custom_column\' , \'custom_mycustompost_column\', 10, 2 ); function custom_mycustompost_column( $column, $post_id )