Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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?

share|improve this question
    
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? –  cj5 Jul 31 '12 at 21:53

1 Answer 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

share|improve this answer
    
Okay =) so the question is how do I represent multiple post types in a query_var string? –  cj5 Aug 1 '12 at 18:38
    
when you build your wp_query's "$args" array, pass another array to post_type. i've updated my response. –  peteroak Aug 1 '12 at 18:48
    
Sorry, I was not clear, but I am using a query string in the URL, not as a PHP array, and I cannot use a WP_Query object because I need the data from user interaction, to check certain checkboxes, for a search filter. Can I use &post_type=event,feature,brief,...? –  cj5 Aug 1 '12 at 19:01
    
ohh i completly missunderstood you. sorry about that. Build the query string like .. better yet, i'll change the response again. –  peteroak Aug 1 '12 at 19:47
    
Hmmm. That's pretty much where I started in asking this question. It doesn't work =/ –  cj5 Aug 2 '12 at 15:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.