This tutorial is a follow up post from my post on how to exclude pages from WordPress search results. In this tutorial today, we will learn how to include custom post types in WordPress search results by adding a filter to the
By default, custom post types are not included in the search results, so we are going to create a function that allows them to be queried and searched by WordPress.
Setting up the Function to Include Custom Post Types in WordPress Search Results
Open up your
functions.php file and paste in the following (sans the opening PHP tag):
This function is simply filtering our search results by adding new arguments to the query results. As you can see from above, the following function will return content from each of these custom post types: post, movies, products and portfolio.
There you have it – now you have included custom post types in your WordPress search results!
Hope you enjoyed the post, and don’t forget to subscribe to these tips and tutorials in the section below!