Created
March 12, 2018 09:51
-
-
Save gareth-gillman/6f5f1524180b6b9cc44d18da9a80880c to your computer and use it in GitHub Desktop.
WordPress search only posts when viewing posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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