Last active
August 27, 2015 18:26
-
-
Save tommcfarlin/9d17aad23873bc37d6c4 to your computer and use it in GitHub Desktop.
[WordPress] Searching custom post types.
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
<?php | |
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