How to Include Specific Custom Post Types in WordPress Search Results
Custom post types are not included in the WordPress search results by default – adding this snippet to your functions.php creates a function that allows specific custom post types to be queried and searched by WordPress.
Instructions
Add this to your functions.php
file
add_filter( 'pre_get_posts', 'custom_post_type_search' ); function custom_post_type_search( $query ) { if ($query->is_search) { $query->set('post_type', array( 'post', 'mycustomposttype1', 'mycustomposttype2', 'mycustomposttype3')); } return $query; }
Hello, This code is work but conflict with bbPress. I add to my functions.php and When I view the topic of bbPress it doesn’t show the content.
@phraisohn – can you post a screendump of the error? (have you enabled debug?)