Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created July 19, 2012 23:13
Show Gist options
  • Save pippinsplugins/3147545 to your computer and use it in GitHub Desktop.
Save pippinsplugins/3147545 to your computer and use it in GitHub Desktop.
ECPT Query Filters
<?php
function ecpt_include_post_types_in_search($query) {
if( $query->is_main_query() && is_search() && $query->query_vars['post_type'] != 'nav_menu_item' ) {
$post_types = get_post_types(array('exclude_from_search' => false), 'objects');
$searchable_types = array();
if($post_types) {
foreach( $post_types as $type) {
$searchable_types[] = $type->name;
}
}
$query->set('post_type', $searchable_types);
}
}
add_action('pre_get_posts', 'ecpt_include_post_types_in_search');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment