Order by two meta keys

I’m not 100% certain what specific order you’re asking for, but you just need to assign an associative array to the ‘orderby’ value. Here’s an example:

$args = array(
    'post_type' => 'brands',
    'meta_query' => array(
        array(
            'key' => 'br_type',
            'value' => 'Aviation'
        ),
        array(
            'key' => 'br_category'
        ),
        array(
            'key' => 'br_name'
        )
    ),
    'posts_per_page' => -1,
    'orderby' => [
        'br_category' => 'ASC',
        'br_name' => 'ASC',
        'br_type' => 'ASC'
    ],
    'order' => 'ASC',
    'fields' => 'ids'
);

Leave a Comment