Skip to content

Instantly share code, notes, and snippets.

@lukad03
Created February 17, 2017 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukad03/bca0c891f6c1d5f7289919efb6d48a25 to your computer and use it in GitHub Desktop.
Save lukad03/bca0c891f6c1d5f7289919efb6d48a25 to your computer and use it in GitHub Desktop.
Wordpress Search Filtering
function prefix_search_filter($query) {
//is_admin check prevents Search Archive in Dashboard from breaking
if (!is_admin() && $query->is_search) {
//Set the Query Options Here, e.g. $query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts', 'prefix_search_filter');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment