Last active
December 27, 2023 17:00
-
-
Save ohryan/e23a8694423283c335965dc8b932f229 to your computer and use it in GitHub Desktop.
The Event Calendar - Query Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'query_loop_block_query_vars', 'tec_order_by_date' ); | |
function tec_order_by_date( $query ) { | |
// ignore if the query block is not using this post type | |
if ( 'tribe_events' !== $query['post_type'] ) { | |
return $query; | |
} | |
// always exclude events with dates in the past | |
$query['meta_key'] = '_EventStartDate'; | |
$query['meta_value'] = date( 'Y-m-d' ); | |
$query['meta_compare'] = '>='; | |
// If date order was chosen in the block settings, change to use the Event date instead of Post date | |
if ( 'date' === $query['orderby'] ) { | |
$query['orderby'] = '_EventStartDate'; | |
$query['order'] = 'ASC'; | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment