Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[WordPress] Searching custom post types.
add_filter( 'pre_get_posts', 'acme_filter_search' );
* If the specified query is a search query, then modify the post_type array
* to support a the 'review' custom post type.
* @since 1.0.0
* @param object $query The current search query.
* @return object $query The modified query supporting CPTs.
function acme_filter_search( $query ) {
if ( ! $query->is_search ) {
return $query;
$query->set( 'post_type', array( 'post', 'page', 'review' ) );
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.