Simple functions to Include custom post types in the search results
- Article
- Comment
Simple functions to Include custom post types in the search results. There are already plenty of articles and forum answers explain you how to include the custom post types on search results. Here I am also going to give you code, but its minimal to work. you can understand well.
The following function includes the custom post types to search query.
function kv_include_custom_post_type_for_search( $query ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'my_custom_post_type', 'movies_review', 'trailer_review', 'summa' )); // Custom Post type names here... } return $query; } add_filter( 'the_search_query', 'kv_include_custom_post_type_for_search' );
That’s it, Very simple code, but works on WordPress 3.9.1 tested. If you have any queries comment below.