有没有办法排除除一个类别之外的所有类别?我想显示一个类别和它的子类别作为下拉菜单,但管理员可能会添加更多的子类别,所以我不想限制他们可以放在那里的唯一ID。
所以我想排除除1及其子类别之外的所有类别。wp\\u list\\u categories()是否可以这样做?
有没有办法排除除一个类别之外的所有类别?我想显示一个类别和它的子类别作为下拉菜单,但管理员可能会添加更多的子类别,所以我不想限制他们可以放在那里的唯一ID。
所以我想排除除1及其子类别之外的所有类别。wp\\u list\\u categories()是否可以这样做?
尝试exclude
中的参数wp_list_categories
. 这将删除选定的类别及其子类。
EDIT: 一定很晚了;这几乎与你想要的相反。要在下拉菜单中仅包括一个类别术语(及其所有子体),可以使用child_of
.
也许有更好的方法可以做到这一点,但这应该是可行的:
$the_terms = get_terms( \'category\', \'child_of=<replace with parent id>\' );
$included_terms = array(\'<replace with parent id>\' );
if( $the_terms )
{
foreach( $the_terms as $the_term )
$included_terms[] = $the_term->term_id;
}
sort( $included_terms );
wp_list_categories(
\'include\' => $included_terms
);
这样可以确保您不必更新ID列表我有一个父类别和几个父类别。每个groundchild都意味着以后要处理的特定方法。父母不应该被挑选出来,这仅仅意味着把孩子分组。我使用wp_dropdown_categories 具有child_of 显示下拉列表。家长的选择可能会让用户感到困惑。wp_dropdown_categories(\'child_of\'=>$ground_parent_id); 如果我添加exclude = $parent_ids, 整个下拉列表都消失了。wp_dropdown_categories(\'c