Skip to content

Instantly share code, notes, and snippets.

@csaborio001
Created July 21, 2020 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csaborio001/efaf2a67028b0c85229100c38a28cf52 to your computer and use it in GitHub Desktop.
Save csaborio001/efaf2a67028b0c85229100c38a28cf52 to your computer and use it in GitHub Desktop.
<?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