WordPress is a popular tool for making websites. By default, WordPress only includes posts and pages in search results. However, you might have custom post types like “Books” or “Recipes”. These might not show up in the search. This guide will help you include custom post types in WordPress search.
What Are Custom Post Types?
Custom post types are different types of content. They are not regular posts or pages. You can create them for unique content. For example, you might have a website about books. Here, the custom post type could be “Books”. This makes it easy to manage and display book-related content.
Why Include Custom Post Types in Search?
Including custom post types in search is useful. It helps users find all content. For example, if your website has recipes, users can find them easily if they are included in search. This makes your website user-friendly.
Steps to Include Custom Post Types in WordPress Search
Follow these simple steps to include custom post types in WordPress search:
Step 1: Backup Your Website
First, backup your website. This is very important. If something goes wrong, you can restore your website. You can use plugins like UpdraftPlus for this.
Step 2: Edit Your Theme’s Functions.php File
Next, you need to edit your theme’s functions.php
file. This file controls many features of your theme. Here are the steps:
- Go to your WordPress Dashboard.
- Navigate to Appearance > Theme Editor.
- Find and open the
functions.php
file.
Step 3: Add Code To Include Custom Post Types In Search
Now, add the following code to your functions.php
file:
function include_custom_post_types_in_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'page', 'your_custom_post_type'));
}
return $query;
}
add_filter('pre_get_posts', 'include_custom_post_types_in_search');
In the code above, replace your_custom_post_type
with the name of your custom post type. For example, if your custom post type is “Books”, the code will be:
function include_custom_post_types_in_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'page', 'books'));
}
return $query;
}
add_filter('pre_get_posts', 'include_custom_post_types_in_search');
Step 4: Save Your Changes
After adding the code, click the “Update File” button to save your changes. Your custom post types should now be included in search results.
Step 5: Test Your Changes
Finally, test your changes. Go to your website and use the search feature. Make sure your custom post types appear in the search results.

Credit: www.wpbeginner.com
Using a Plugin to Include Custom Post Types in Search
If you are not comfortable with code, you can use a plugin. There are many plugins that help you include custom post types in search. One popular plugin is “Search Everything”.
Steps To Use The “search Everything” Plugin
- Go to your WordPress Dashboard.
- Navigate to Plugins > Add New.
- Search for “Search Everything”.
- Install and activate the plugin.
After activating the plugin, go to Settings > Search Everything. Here, you can configure the plugin to include custom post types in search.

Credit: thomasgriffin.com
Frequently Asked Questions
How Do I Add Custom Post Types To WordPress Search?
You can use the `pre_get_posts` action hook. Add code to your theme’s `functions. php` file.
What Plugin Helps Include Custom Post Types In Search?
The “Search Everything” plugin is popular. It includes custom post types in search results.
Is There A Way To Include Only Specific Custom Post Types?
Yes, modify your search query to include only the custom post types you want.
Can I Exclude Certain Post Types From WordPress Search?
Yes, you can. Adjust the search query to exclude specific post types using `pre_get_posts`.
Conclusion
Including custom post types in WordPress search is easy. You can do it by editing the functions.php
file or using a plugin. This helps users find all types of content on your website. Follow the steps in this guide to make your custom post types searchable. Happy blogging!