Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.