Wordpress only shows practice categories with practices attached to it

Viewed 15

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;
}

1 Answers

Try adding 'hide_empty' => false, to your query:

$practiceCategories = get_terms(array(
     'taxonomy' => 'practice_category',
     'orderby' => 'name',
     'hide_empty' => false
));
Related