Skip to content

Instantly share code, notes, and snippets.

@gareth-gillman
Created March 12, 2018 09:51
Show Gist options
  • Save gareth-gillman/6f5f1524180b6b9cc44d18da9a80880c to your computer and use it in GitHub Desktop.
Save gareth-gillman/6f5f1524180b6b9cc44d18da9a80880c to your computer and use it in GitHub Desktop.
WordPress search only posts when viewing posts
function gg_postssearch($query) {
if( is_single( 'post' ) || is_post_type_archive( 'post' ) {
if( $query->is_search ) {
$query->set( 'post_type', 'post' );
}
return $query;
}
}
add_filter( 'pre_get_posts',' gg_postssearch' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment