You can do this with a meta_query
. The get_posts()
function accepts everything that WP_Query accepts so it could look something like this:
$orders = get_posts( array(
'numberofposts' => -1,
'posts_per_page' => -1,
'post_type' => 'executive-orders',
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'AND',
'eo_type' => array(
'key' => 'eo_type',
'value' => 'county',
),
'second_type' => array(
'key' => 'second_key',
'type' => 'NUMERIC',
),
),
'orderby' => array( 'eo_type' => 'DESC', 'date' => 'ASC' ),
) );
With the Meta Query we can define our key value pairs just like we did with meta_key
and meta_value
. We give them a named index eo_type
so that we can reference it in the orderby
parameter. We can add as many meta values as we need and can even nest further.