All I want is to be able to easily get the top-level categories from my page. In this case, any that has no parent. Isn't there a simple way to do this without wp_list_categories?
Alternatively, is there a way to get wp_list_categories to stop returning all that data and just give me the IDs?
Actually, I think I've got it. My query was working fine, I just forgot to exclude tags in my search. Here's what worked:
$result = $wpdb->get_results("SELECT t.name, t.term_id, tt.count, slug FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.parent='0' AND tt.count > 0 AND tt.taxonomy='category' ORDER BY t.name ASC");
Returns categories with no parent that include at least one child
excellent code!
thank you so much
how can i exclude some categories from that result?
$root_categories = get_categories( array(
'parent' => 0,
) );
To exclude categories, you can do:
$root_categories = get_categories( array(
'parent' => 0,
'exclude' => array( 1, 2, 3 ),
) );