I am trying to display results using multiple custom fields while ordering the results by the first custom field (startdate). The recommendations that I have seen led me to try this:
$args = array(
'category_name' => 'Events',
'posts_per_page' => 6,
'meta_key' => 'startdate',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'startdate',
'value' => $date,
'compare' => '>='
),
array(
'key' => 'closedate',
'value' => $date,
'compare' => '>='
)
),
'orderby' => 'meta_value',
'order' => 'desc'
);
The problem is that without the meta_key parameter the results filter by the default, the date of the post. When I add the meta_key parameter to sort the results, I get every post with a meta_key equal to startdate. It seems that by adding those meta_key parameter the statement completely ignores the conditions in the meta_query array. How do I get the query to sort by startdate without pulling all of the posts that have a meta_key equal to startdate?