As I already pointed in the comment, all you need to do is change your orderby
parameter so that the meta_prio
is the first item and followed by the meta_start
. So your orderby
should look like:
// This array forms an ORDER BY clause with each array item being a column that
// MySQL use when sorting the posts/results.
'orderby' => array(
// This is the first column, which has the highest priority and sorts by the
// meta high_prio.
'meta_prio' => 'DESC',
// This is the second column, which sorts by the meta date_start, after MySQL
// sort the results by the meta high_prio.
'meta_start' => 'ASC',
)
So with the above example, the generated ORDER BY
clause would look something like ORDER BY <meta_prio column> DESC, <meta_start column> ASC
and MySQL would first sort the results by the high_prio
meta and then sort the sorted results by the date_start
meta.
And remember that the array key used in your orderby
must match the one in your meta_query
, if you’re sorting the results by the meta query clauses in the meta_query
array. Additionally, make sure you set the proper type
in your meta query clauses; e.g. if the value is a date like 2020-03-12 09:30
, then you’d set the type to DATETIME
(i.e. 'type' => 'DATETIME'
):
'meta_query' => array(
'relation' => 'OR',
'meta_start' => array(
'key' => 'date_start',
'type' => 'DATETIME',
),
'meta_prio' => array(
'key' => 'high_prio',
'type' => 'NUMERIC',
)
),
// Make sure the array keys match those in the above meta_query array.
'orderby' => array(
'meta_prio' => 'DESC',
'meta_start' => 'ASC',
),