Skip to content

Instantly share code, notes, and snippets.

@Tsunamijaan
Created January 5, 2019 08:50
Show Gist options
  • Select an option

  • Save Tsunamijaan/206c90629fb337ddf7f5decb8f691c28 to your computer and use it in GitHub Desktop.

Select an option

Save Tsunamijaan/206c90629fb337ddf7f5decb8f691c28 to your computer and use it in GitHub Desktop.
Filter search results by post type
function search_posts_filter( $query ){
if ($query->is_search){
$query->set('post_type',array('post','custom_post_type1', 'custom_post_type2'));
}
return $query;
}
add_filter('pre_get_posts','search_posts_filter');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment