I'm using get_posts method to get my post and events. But because of different name of arguments (event-categories and category_name) or metas (event_end and _end_ts) I used two arrays of argument and two calling of get_posts. Everything works fine but I need to order result by meta key and because of merging two arrays of posts I get sorted posts and next sorted events. Is there any option to get sorted all (better args for query or sort of array by two metas)?
This code works fine - it returns me two sorted arrays by begin date of given category in specific date range (events have time in seconds)
if($toDate != date('Y/m/d',strtotime(0)))
{
$secondCondition = array(
'key' => 'event_begin',
'value' => $toDate,
'compare' => '<=',
'type' => 'date'
);
$secondCondition2 = array(
'key' => '_start_ts',
'value' => strtotime($toDate),
'compare' => '<=',
'type' => 'numeric'
);
}
else
{
$secondCondition = "";
}
$query1 = array(
'category_name' => $category,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'event_begin',
'meta_query' => array(
array(
'key' => 'event_end',
'value' => $fromDate,
'compare' => '>=',
'type' => 'date'
),
$secondCondition
)
);
$query2 = array(
'post_type' => 'event',
'event-categories' => $category,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => '_start_ts',
'meta_query' => array(
array(
'key' => '_end_ts',
'value' => strtotime($fromDate),
'compare' => '>=',
'type' => 'numeric'
),
$secondCondition2
)
);
$postGroup1 = get_posts( $query1);
$postGroup2= get_posts( $query2);
$mergedPosts = array_merge($postGroup1, $postGroup2);