The other day I had a client come to me with a problem. They were trying to search for an article on their site, but it wasn’t showing up in the search results. They typed in the exact title, but they still couldn’t find it.
After some troubleshooting, I found out the post in question was actually part of a custom post type. By default the WordPress search results only returns posts and pages, but you can easily update it to also search through custom post types.
Let’s say your custom post type name is “article”. Using the
pre_get_posts filter, you can change the post types that the WordPress search function uses.
In your functions.php file, add the following code:
To learn more about how filters work, check out my post here. You can do lots of different things with the
pre_get_posts filter, such as changing the number of posts a custom post type archive displays. Check out the Codex for more information.