Created
November 17, 2012 22:45
-
-
Save webgurus/4100946 to your computer and use it in GitHub Desktop.
search only custom post types in wordpress
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
add_filter( 'pre_get_posts', 'cpt_search' ); | |
/** | |
* tgm_cpt_search function. | |
* | |
* This function modifies the main WordPress query to include an array of post types instead of the default 'post' post type. | |
* | |
* @param mixed $query The original query | |
* @return $query The amended query | |
* | |
*/ | |
function cpt_search( $query ) { | |
if ( $query->is_search ) | |
$query->set( 'post_type', array( 'post_type1', 'post_type2', 'post_type3') ); | |
return $query; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment