Skip to content

Instantly share code, notes, and snippets.

@Robzelf
Last active August 26, 2021 21:05
Show Gist options
  • Save Robzelf/65065e5a5fef08947be8c6c022f10d33 to your computer and use it in GitHub Desktop.
Save Robzelf/65065e5a5fef08947be8c6c022f10d33 to your computer and use it in GitHub Desktop.
Sort entries by date and skip everything before today.
function update_agenda_archive($query) {
if ( !is_admin() && $query->is_post_type_archive('agenda') ) {
$_today = date('Ymd');
$query->set('meta_key', 'event__start_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
$query->set('meta_query', array(
array(
'key' => 'event__start_date',
'value' => $_today,
'compare' => '>=',
'type' => 'date' ),
));
}
}
add_action( 'pre_get_posts', 'update_agenda_archive' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment