https://www.udemy.com/become-a-wordpress-developer-php-javascript/learn/v4/t/lecture/7440942?start=0
<?php
function university_adjust_query( $query ) {
// Only run if on front end of the site
// This query only run on our intended URL
// $query->is_main_query() is making sure that we are only effecting the default query not any custom queries we may have written
if( !is_admin() && is_post_type_archive( 'event' ) && $query->is_main_query() ) {
// $query->set('name-of-the-query-parameter-you-want-to-change', 'value-you-want-to-use');
$today = date('Ymd');
$query->set('meta_key', 'event_date');
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');
$query->set('meta_query', array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
));
}
}
// Right before getting the posts
add_action( 'pre_get_posts', 'university_adjust_query' );