Created
July 21, 2020 04:35
-
-
Save csaborio001/efaf2a67028b0c85229100c38a28cf52 to your computer and use it in GitHub Desktop.
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 | |
function( $query ) use ( $custom_post_type_name ) { | |
if ( ! is_admin() && $query->is_main_query() ) { | |
if ( ! empty( $custom_post_type_name) && $query->is_post_type_archive( $custom_post_type_name ) ) { | |
$date_sydney_now = ( new \DateTime( 'now', new \DateTimeZone( 'Australia/Sydney' ) ) )->format('Ymd'); | |
/** Default to upcoming events. */ | |
$compare = '>='; | |
if ( 'true' === $_GET['archive'] ) { | |
/** We need to get everything older than today. */ | |
$compare = '<='; | |
} | |
$query->set( 'posts_per_page', 5 ); | |
$query->set( 'meta_key', 'start_date_picker' ); | |
$query->set( 'orderby', 'meta_value' ); | |
$query->set( 'order', 'DESC' ); | |
$query->set( | |
'meta_query', | |
array( | |
array( | |
'key' => 'start_date_picker', | |
'value' => $date_sydney_now, | |
'compare' => $compare, | |
) | |
) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment