[wp-hackers] including the CPTs in the search result

IC IC icwordpress at gmail.com
Tue Dec 6 23:21:03 UTC 2011


Is the following method technically sound and OK as a practice on a
traffic heavy web site? Any more efficient ways you can recommend?

function filter_search($query) {
    if ($query->is_search) {
	$query->set('post_type', array('post',
'custom_type_1_here','custom_type_2_here'));
    };
    return $query;
};
add_filter('pre_get_posts', 'filter_search');

This will also make sure that the pages are excuded from the search
result which is obviously optional.


More information about the wp-hackers mailing list