Categories: Wordpress Support

How to include custom post type in Search Results

By default in WordPress, the search results shows for pages & defualt post types. So if you create any custom post type it doesn’t include automatically.

The the_search_query filter helps you to include your custom post types in search results. Just copy and paste the below code by renaming your post_type in your theme functions.php file.

// MAKE CUSTOM POST TYPES SEARCHABLE
function add_search_results( $query ) {
 if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' )); } 
 return $query;
}
add_filter( 'the_search_query', 'add_search_results' );

 

This post has already been read 3257 times!

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

More Posts

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

Share
Published by
Mehedi Hasan

Recent Posts

WP Share A Friend – A Way to Capture Lead

What is Lead Capture: In general sense lead capture designates a process or way of…

5 years ago

Unlimited Modal POPUPS on MouseClick

Introduction Unlimited Modal POPUPS on MouseClick: Everyone knows about popup during site visits and most…

5 years ago

WordPress Pregnancy Calculator Plugin

Brief about Pregnancy Calculator : This WordPress Pregnancy Calculator plugin allows users to display an…

5 years ago

Interactive Service Plugin with Hover Effects VC

Introduction About this Service Plugin: This Visual Composer Service Plugin works as an addon to…

6 years ago

WP Dynamic Query String

Introduction of Dynamic Query String : This plugin allows user to set dynamic query string…

6 years ago

How to make scroll PDF in iFrame for iPAD Safari

There is an occasional bug for iPhone and iPad even they are designed as well and…

7 years ago