Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here is the code in am using

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

query_posts($arg);

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?

share|improve this question

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() ):
        the_post();
        if( has_term( $status, 'vr_listing_status' ) ):
            the_title();
        endif;
    endwhile;
    rewind_posts();
endforeach;

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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