order posts on meta_query with relation
-
[Moved from Your WordPress which is NOT a support forum.]
I am trying to list posts in my agenda, ordered by meta_key
dateFrom
.The following code works correctly:
$agenda_loop = new WP_Query( array( 'cat' => $thisCatID, 'paged' => $paged, 'meta_key' => 'dateFrom', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'dateFrom', 'value' => date('Y-m-d'), 'compare' => '>=', ), ), ) );
However, if I add a condition (I also want to list events whose
dateFrom
is in the past, if theirdateTo
is set and in the future), the order is not working anymore:$agenda_loop = new WP_Query( array( 'cat' => $thisCatID, 'paged' => $paged, 'meta_key' => 'dateFrom', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'dateFrom', 'value' => date('Y-m-d'), 'compare' => '>=', ), array( 'key' => 'dateTo', 'value' => date('Y-m-d'), 'compare' => '>=', ), ), ) );
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘order posts on meta_query with relation’ is closed to new replies.