WP Query multiple orderby based on meta value

11 Views Asked by At

In my custom post type, I have 2 custom fields:

  1. iso_flag (= iso codes like be, us, ...)
  2. ranking (1, 2, ...)

I want to write a WP Query, that first orders by 'iso_flag' (alphabetical) and secondly orders by ranking (numeric). How can I achieve that?

This is what I have so far:

$args = array(
    'post_type' => 'commission_member',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'commission_member_category',
            'field' => 'term_taxonomy_id',
            'terms' => $commission_category
        )
    ),
    'country_clause' => array(
        'meta_key' => 'iso_flag',
        'orderby' => 'meta_value',
    ),
    'ranking_clause' => array(
        'meta_key' => 'ranking',
        'orderby' => 'meta_value_num',
    ),
    'orderby' => array(
        'country_clause' => 'DESC',
        'ranking_clause' => 'ASC'
    )
);
0

There are 0 best solutions below