I am running into one issue with pre_get_post filter.
Actually I have 4 post types. Post, Pages, Events, and Venue. I created one custom field called city for event and venue post type.
When creating custom field I have one option to select post type on which I want to display that custom field.
Now, on the front end part I added one filter on pre_get_posts and modified the main query to get all posts from specific city.
All things are working perfectly on events and venue listing and single page but this filter also applies on post and pages as well.
What I want is, **I want to remove the this filter from the post type which are not included with that custom field.
I have tried with $wp_query->query_vars['page_id'] this code but its not working any more.
Can any one help me to sort this our ?
FYI: My code looks like,
add_action( 'pre_get_posts', 'citywise_post_filter' );
function citywise_post_filter($query) {
global $wp_query;
if( isset( $_REQUEST['city_filter'] ) ){
$city = $_REQUEST['city_filter'];
}else{
$city = $_SESSION['CURR_CITY'];
}
if ( !is_admin() ){
$query->set( 'meta_key', '_ct_selectbox_52f65ae267764' );
$query->set( 'meta_value', $city );
return;
}
}
Thanks, Aezaz