Skip to content

Instantly share code, notes, and snippets.

@ChrisCree
Last active September 30, 2015 21:39
Show Gist options
  • Save ChrisCree/b764da8da3124d7c39a0 to your computer and use it in GitHub Desktop.
Save ChrisCree/b764da8da3124d7c39a0 to your computer and use it in GitHub Desktop.
How to only return blog posts for the default WordPress search function.
<?php
// Don't copy opening PHP tag above
// Add below code to your theme's functions.php file.
// Only show blog posts in search results
add_filter( 'pre_get_posts','wsm_post_only_search_filter' );
function wsm_post_only_search_filter( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', 'post' );
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment