Here is the code in am using

$arg= array(
    'post_type' => 'vr_listing',
    'tax_query' => array(
            'taxonomy' => 'vr_listing_status',
            'field' => 'slug',
            'terms' => array( 'Active', 'Pending','Sold')
    'meta_key' => 'vr_list_price',
    'orderby' => 'meta_value_num',
    'order' => 'DESC'


Each listing has a particular status assigned to it i.e Active,pending,status(different terms in custom taxonomy) What i want to achieve is to first order by price using meta key and at the same time i want to get the results from custom taxonomy from different terms but one by one. e.g first i want to achieve all the results from Active term and then pending and then sold

Any ideas how can i achieve this?

1 Answer 1


I think the simplest way would be to run the loop for each status and only output posts that match the current status:

$statuses = array( 'Active', 'Pending', 'Sold' );
foreach( $statuses as $status ):
    echo $status;
    while( have_posts() ):
        if( has_term( $status, 'vr_listing_status' ) ):

A couple of additional notes - if this is the main query, alter it via the pre_get_posts action rather than using query_posts in the template. If this is an additional query and not the main query, use WP_Query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.