Skip to content

Instantly share code, notes, and snippets.

@stuartduff
Last active August 7, 2016 19:08
Show Gist options
  • Save stuartduff/3608310 to your computer and use it in GitHub Desktop.
Save stuartduff/3608310 to your computer and use it in GitHub Desktop.
seacrh filter posts only
// Search filter returning posts only, not pages
function sd_limit_search_results_post_type( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', 'post' );
}
return $query;
}
add_filter( 'pre_get_posts', 'sd_limit_search_results_post_type' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment