Custom post_type search’s $wp_query->query_vars do not correspond

I have been having this issue, with integrating events manager among my other post types, where the other custom post types show up in the $wp_query->query_vars array, except for the event manager ones. The search works, and does grab the event post types, but for some strange reason the post_type query variable does not include “event”. Why is this happening? Below is the code I am using to force the query to use the event post type:

function _search_all($query) {

if($query->is_search()) {
$query->set("post_type", array(EM_POST_TYPE_EVENT, FEATURES_ID, BRIEFS_ID, CAMPUS_NEWS_ID));
}

return $query;
}
add_action("pre_get_posts", "_search_all");

EM_POST_TYPE_EVENT = ‘event’, and is registered in the plugin code, and it shows up everywhere else on the site, but in the search result’s query variables. The other 3 post types are custom as well. The ‘event’ post type is set to exclude_from_search = false, so I am at a complete loss here, as to why I cannot get the event post type included in any search.

Read More

Just for clarification

Here is an example query string

  ?s=science&post_start_date=&post_end_date=&post_type[]=event

and the result of $wp_query->query_vars is

array(6) { ["post"]=> string(4) "post" 
           ["page"]=> string(4) "page" 
           ["attachment"]=> string(10) "attachment" 
           ["features"]=> string(8) "features" 
           ["briefs"]=> string(6) "briefs" 
           ["campus_news"]=> string(11) "campus_news" 
 } 

Where’s my event post_type?

Related posts

Leave a Reply

1 comment

  1. build the url parameters something like this :

    ?post_type[]=event&post_type[]=feature&post_type[]=brief
    

    Then $searchposttypes = $_GET['post_type'] will have an array. pass it on to the wp_query

    i should add that you should validate the $_GET parameters before going on with it.

    reference : wp_query – type parameters