Skip to content

Instantly share code, notes, and snippets.

@webgurus
Created November 17, 2012 22:45
Show Gist options
  • Save webgurus/4100946 to your computer and use it in GitHub Desktop.
Save webgurus/4100946 to your computer and use it in GitHub Desktop.
search only custom post types in wordpress
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