is_main_query() ){ return; } // remove comments if you want to retrieve a specific post type /* if ( !is_post_type_archive( 'event' ) ){ return; } */ $city = get_query_var( 'city' ); // add meta_query elements if( !empty( $city ) ){ $query->set( 'meta_key', 'city' ); $query->set( 'meta_value', $city ); $query->set( 'meta_compare', 'LIKE' ); } } add_action( 'pre_get_posts', 'myplugin_pre_get_posts', 1 );