Skip to content

Instantly share code, notes, and snippets.

@mehul0810
Created June 17, 2017 03:22
Show Gist options
  • Save mehul0810/b1bab1003e79716b7efbc68e1d9e2a20 to your computer and use it in GitHub Desktop.
Save mehul0810/b1bab1003e79716b7efbc68e1d9e2a20 to your computer and use it in GitHub Desktop.
This script will filter default WordPress Search by the post type which you want to search for.
<?php
/**
* Filter WordPress Search for specific post types
*
* @param $query
*
* @return mixed
*/
function bloggerpro_only_post_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', 'post' );
}
return $query;
}
add_filter( 'pre_get_posts', 'bloggerpro_only_post_search' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment