How to Create a Custom Search for WordPress Custom Post Type?
wordpress-custom-post-type-search-enable

In WordPress, we add custom post types for various purposes. But WordPress custom post type did not automatically show this post in the search result. In this case, we have to enable it to show in the search result.

HOW?

Add the below codes in your theme’s functions.php file. If you have videos, news, and articles for custom post type then add them in the array like below.

function themejelly_search_filter($query) {
if ($query->is_search) {
$query->set( 'post_type', array( 'post', 'page', 'videos', 'news', 'aticles') );
}
return $query;
}
add_filter('parse_query', 'themejelly_search_filter');

Here themejelly_search_filter is the name of functions. It can be any name.


Themejelly Staff

Aminul Islam is a WordPress theme developer and developed this website's theme. He also the content writer of this website.


You May Also Like!
How to Change the Footer in WordPress Admin Panel

The Footer of the WordPress dashboard area shows the message of the credit of the theme. We can change this… details

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

*