there is this loop which sorts by the date. But I want to throw in a specific meta key for a even higher priority. The meta_key "high_prio" should move it to the top of the sorting. (I hope that makes sence).
Let's speak some code:
$loop = new WP_Query( array(
'post_type' => 'event',
'posts_per_page' => 3,
'cat' => '4',
'orderby' => array( 'meta_start' => 'ASC','meta_prio' => 'DESC'),
'meta_query' => array(
'relation' => 'OR',
'meta_start' => array(
'key' => 'date_start',
'type' => 'numeric'
),
'meta_prio' => array(
'key' => 'high_prio',
'type' => 'numeric'
)
)
));
The SQL looks like this now:
SELECT SQL_CALC_FOUND_ROWS pdh50NA5_posts.ID
FROM pdh50NA5_posts
LEFT JOIN pdh50NA5_term_relationships
ON (pdh50NA5_posts.ID = pdh50NA5_term_relationships.object_id)
INNER JOIN pdh50NA5_postmeta
ON ( pdh50NA5_posts.ID = pdh50NA5_postmeta.post_id )
WHERE 1=1
AND ( pdh50NA5_term_relationships.term_taxonomy_id IN (4) )
AND ( pdh50NA5_postmeta.meta_key = 'date_start'
OR pdh50NA5_postmeta.meta_key = 'high_prio' )
AND pdh50NA5_posts.post_type = 'event'
AND (pdh50NA5_posts.post_status = 'publish'
OR pdh50NA5_posts.post_status = 'acf-disabled'
OR pdh50NA5_posts.post_status = 'private')
GROUP BY pdh50NA5_posts.ID
ORDER BY CAST(pdh50NA5_postmeta.meta_value AS SIGNED) ASC, CAST(pdh50NA5_postmeta.meta_value AS SIGNED) DESC
LIMIT 0, 3
I am not good at SQL. I understand the basics but the order part is too much.
Maybe this has to be done differently. Thanks in advance!
orderby
items:'orderby' => array('meta_prio' => 'DESC', 'meta_start' => 'ASC),
?echo $loop->request;
?