0

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?

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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