If you’re using Custom Post Types in your WordPress site, you might assume that your site search will display those posts along with the standard posts and pages in search results. However, WordPress actually has to be told to not only search custom post types, but a little extra work is needed to find in search all of the additional information that you might be storing in custom fields. Here’s a quick and easy way to search EVERYTHING within Custom Post Types. I encountered this issue last month when I was working through QA tasks; the client was searching a specific keyword phrase and wondering why one of the most prominent pages on the site (that featured that phrase) wasn’t being returned in results. I saw that the page was an archive for the custom post type “Products” and added that to the array of post types available to the search query: function wds_cpt_search( $query ) { if ( is_search() && $query->is_main_query() && $query->get( 's' ) ){ $query->set('post_type', array('post', 'page', 'product')); } return $query; }; add_filter('pre_get_posts', 'wds_cpt_search'); But I still wasn’t seeing the page show up in results. Looking at the Product post type,
Share This