I'm trying to get all the terms of a custom taxonomy (ediciones
) but ordered by two ACF fields: edicion_ano
(year field) and edicion_numero
(number field). First should order by year and next by the number field.
I understand from ACF (5.5.X) it's possible to use meta_query
and I'm ussing version 5.5.14.
In the new version of ACF (5.5.x) now uses term meta and WP allows meta queries for terms, so these work-arounds should no longer be needed. (source)
Right now I'm using this code:
$args = array(
'taxonomy' => 'ediciones',
'hide_empty' => false,
'meta_query' => array(
'relation' => 'AND',
'edicion_ano_param' => array(
'key' => 'edicion_ano',
'compare' => 'EXISTS',
),
'edicion_numero_param' => array(
'key' => 'edicion_numero',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'edicion_ano_param' => 'DESC',
'edicion_numero_param' => 'DESC',
),
);
$ediciones = get_terms($args);
Using the same meta_query
but with get_posts()
it's working fine.
Actually with get_terms()
show me a warning but I don't know why: Warning: strtolower() expects parameter 1 to be string, array given in .../class-wp-term-query.php on line 824
If I try order just for one field works fine with this code:
$args = array(
'taxonomy' => 'ediciones',
'hide_empty' => false,
'meta_key' => 'edicion_ano',
'orderby' => 'meta_value',
'order' => 'DESC',
);
$ediciones = get_terms($args);
But I need order by both fields. Any idea what I'm doing wrong or how can make this works how I need?
Thanks!