Include or exclude custom post types in wordpress search result
Defining post types in search query allows you to include or exclude the custom post types in wordpress search result. Just add this function to functions.php
// MAKE CUSTOM POST TYPES SEARCHABLE
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'site','plugin', 'theme','person' ));
}
return $query;
}
add_filter( 'the_search_query', 'searchAll' );
$query->set( 'post_type', array( 'site','plugin', 'theme','person' ));
we can add or remove the post-types to be searched. Short but effective.
Comments
Post a Comment