Simple functions to Include custom post types in the search results |
X

Congrats, You are Subscribed to Receive Updates.

Simple functions to Include custom post types in the search results


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.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar