I am trying to get list of only child categories of custom taxonomy, but getting output as all parent and child terms.
$countries = get_categories(array(
'hide_empty' => true,
'taxonomy' => 'locations-category',
'orderby' => 'name',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'locations-category',
'terms' => 0,
'field' => 'parent',
'compare' => '!='
)
)
));
echo "<pre>";
print_r($countries);
echo "</pre>";`
Tried this as well but getting error as undefined variable:
$categories = get_terms('locations-category', 'parent!=0');
echo "<pre>";
print_r($countries);
echo "</pre>";
Basically I want to get categories where 'parent' != 0
2
Answers
Probably best to use PHP to filter the results from
get_category()
(untested):