I have a problem with my function is use for dropdown menus in 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. Im a big php noob. 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:
$practiceCategories = get_terms(array(
'taxonomy' => 'practice_category',
'orderby' => 'name',
'hide_empty' => false
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.