Last active
September 30, 2015 21:39
-
-
Save ChrisCree/b764da8da3124d7c39a0 to your computer and use it in GitHub Desktop.
How to only return blog posts for the default WordPress search function.
This file contains hidden or 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
<?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