Hi,
I have an events listing grid that shows upcoming events. On some days we have more than one event, but in this case events are in the wrong time order i.e. An event at 7pm shows before an event at 2pm.
I was advised to take a look at using bricks/posts/query_vars and have tried to implement it but with no luck.
I’m not totally sure how the bricks side of it should be set up. I have a div with ID 'event-grid-loop. This div has the ‘query loop’ setting activated with Query Type: Posts, Post type: Events, Order by: Date (default), Order: Descending (default), Posts per page: 6.
Then in my functions.php -
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if( $element_id !== 'event-grid-loop') return $query_vars;
$query_vars['meta_query'] = [
'relation' => 'AND',
'date' => array(
'key' => 'date',
'compare' => 'EXISTS',
),
'time' => array(
'key' => 'time',
'compare' => 'EXISTS',
),
];
$query_vars['orderby'] = [
'date' => 'ASC',
'time' => 'DESC'
];
return $query_vars;
}, 10, 3 );
Can’t see any change in the order of the grid (I’ve turned off cache).
Staging that I’m testing this on: Events - The Court House
and the production: https://courthousebangor.com/events/
Thanks in advance!