[英]Wordpress only shows practice categories with practices attached to it
I have a problem with my function is use for dropdown menus in wordpress.我的 function 用于 wordpress 中的下拉菜单有问题。 It only shows practice categories that have practices attached to it.
它仅显示附有实践的实践类别。 If i remove the last forloop, it does show all the practice categories and vice-versa.
如果我删除最后一个 forloop,它会显示所有练习类别,反之亦然。 Im a big php noob.
我是一个大 php 菜鸟。 Thanks.
谢谢。
function lr_get_practice_select_data() {
$practiceCategories = get_terms(array(
'taxonomy' => 'practice_category',
'orderby' => 'name'
));
$out = array();
foreach ($practiceCategories as $category) {
$out[] = array(
'value' => 'category_' .$category->term_id,
'class' => 'category',
'name' => $category->name
);
$practicesInCategory = lr_get_practices_by_category($category->term_id);
foreach ($practicesInCategory as $practice) {
$out[] = array(
'value' => $practice->ID,
'class' => 'practice',
'name' => $practice->post_title
);
}
}
return $out;
}
Try adding 'hide_empty' => false
, to your query:尝试将
'hide_empty' => false
添加到您的查询中:
$practiceCategories = get_terms(array(
'taxonomy' => 'practice_category',
'orderby' => 'name',
'hide_empty' => false
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.