Hi,
I previously setup a masonry element to display events using The Events Calendar. The events were sorted by date with the most recent event first. The sorting function is no longer working correctly and displays events by the date published, not the date of the event like before. Has something changed? The masonry element is on the top of the homepage at the link provided.
Thanks!
Hey bcgallaher,
Thank you for the inquiry.
The masonry element does not support sorting entries by their starting date by default. You can see the available sorting option in the element’s Content > Sorting > Order by settings. You may need to add the filter below to change the masonry query a bit and sort the events by their starting date.
/* query events by starting date */
function avia_masonry_entries_query_mod( $query, $params ) {
if(! is_page( [23, 8] ) )
{
return $query;
}
$include = array();
$events = tribe_get_events( [
'posts_per_page' => $query["posts_per_page"],
'start_date' => 'now',
] );
foreach($events as $event) {
$include[] = $event->ID;
}
unset($query['tax_query']);
$query['post__in'] = $include;
return $query;
}
add_filter('avia_masonry_entries_query', 'avia_masonry_entries_query_mod', 10, 2);
Make sure to include the ID of the page containing the masonry with events in the is_page conditional function above.
Best regards,
Ismael