How can I use WP_Query to sort ‘event’ custom post type by date?

Found a ready made solution posted in the codex: https://developer.wordpress.org/reference/hooks/pre_get_posts/

The trick here is the pre_get_posts hook which modifies the query variable ‘after the query variable object is created, but before the actual query is run’ so that if the post type is an event, it sorts in the same way I’d been doing already. Put this in functions.php

function university_adjust_queries($query){
   if ( ! is_admin() && is_post_type_archive( 'event' ) && $query->is_main_query() ) {
        $query->set( 'meta_key', 'event_date' );
        $query->set( 'orderby', 'meta_value_num' );
        $query->set( 'order', 'ASC');
        $query->set( 'meta_query', array(
            array(
                'key'     => 'event_date',
                'compare' => '>=',
                'value'   => date('Ymd'),
                'type'    => 'numeric',
            )
        ) );
   }
}
add_action( 'pre_get_posts', 'university_adjust_queries' );

Thanks to saddamcrr7

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)