Order 2 meta_queries differently in WP_Query?

I have a custom WP_Query with 2 different meta queries. I want to order the results of both queries differently. The first meta_query I want to order by a custom field (high integer – low integer). The second meta_query I want to order by date. Below the code I currently have. For some reason it is ordering both meta_query by meta_value_num. How can I order both meta queries differently, within the same WP_Query? Or do I actually have to make 2 different WP queries?

<?php
$sticky = get_option( ‘sticky_posts’ );
$term = get_queried_object();
/* Query sticky posts */
$the_query = new WP_Query( array( ‘post__in’ => $sticky, ‘ignore_sticky_posts’ => 1, ‘posts_per_page’ => 5, ‘post_type’ => ‘ads’, ‘tax_query’ => array(
//Get posts by term slug
‘relation’ => ‘OR’,
array (
‘taxonomy’ => ‘ad_cat’,
‘field’ => ‘slug’,
‘terms’ => $term->slug,
)
),
‘meta_query’ => array(
//Get posts with custom field key ‘cc_aff_stick_top’
‘relation’ => ‘OR’,
‘is_aff’ => array(
‘key’ => ‘cc_aff_stick_top’,
‘compare’ => ‘EXISTS’,
),
//Get posts without key
‘is_not_aff’ => array(
‘key’ => ‘cc_aff_stick_top’,
‘compare’ => ‘NOT EXISTS’,
),
),
//Order by CF cc_aff_stick_top and otherwise by date
‘orderby’ => array(
‘meta_value_num’ => ‘ASC’,
‘date’ => ‘DESC’
),
) );
// The Loop
if ( $the_query->have_posts() ) {

Read more here:: Order 2 meta_queries differently in WP_Query?

Leave a Reply

Your email address will not be published. Required fields are marked *