Created
June 17, 2017 03:22
-
-
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.
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 | |
/** | |
* 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