I'm writing a taxonomy query that looks like this:
$args = array(
'orderby' => 'name',
'parent' => 0,
'order' => 'ASC');
$categories = get_categories( $args );
I have taxonomy data so it should be returning something, but it isn't. I output the $wpdb->last_query and the query that get_categories() built is this:
SELECT t.*, tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy IN ('category') AND tt.parent = '0' AND tt.count > 0
ORDER BY t.term_order ASC;
The ordering on t.term_order fails because there is no term_order column in wp_terms. The only way I could get it to work was to add a 'get_terms_orderby' filter and have it return 't.name'. Then it generates the correct SQL:
SELECT t.*, tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy IN ('category') AND tt.parent = '0' AND tt.count > 0
ORDER BY t.name ASC;
Is there something wrong with the code that I wrote, or is there a bug in get_categories()?
Thanks!