Wildcard with LIKE operator in Meta query

Have you var_dumped $location?

WP_Query‘s meta_query uses the class WP_Meta_Query, which automatically appends and prepends ‘%’ to any string passed to it:

// From wp-includes/class-wp-meta-query.php:610 
switch ( $meta_compare ) {
            // ...
            case 'LIKE' :
            case 'NOT LIKE' :
                $meta_value="%" . $wpdb->esc_like( $meta_value ) . '%';
                $where = $wpdb->prepare( '%s', $meta_value );
                break;
            // ...
}

So maybe try using (string) $location as the sql statement is prepared, and expecting a string — that’s what the %s means in the line $where = $wpdb->prepare( '%s', $meta_value );. You can cast your variable to a string like this:

$location = (string) preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['location']);

error code: 523