What Was Happening
Search queries like “virus” or “case study” didn’t return any product results, even though matching products were published and indexed. Meanwhile, unrelated static pages showed up instead. Custom search behavior that once prioritized products had stopped working after some plugin or theme updates.
What We Found
🔍 No Priority for CPTs
The theme’s search.php and functions.php didn’t include any logic to elevate custom post types like “product” over standard posts and pages.
⚙️ WP_Query Was Basic
The query wasn’t configured to weight or include custom fields or taxonomies, leading to inconsistent results.
How We Fixed It
1. Adjusted the Search Query
We added a pre_get_posts filter in functions.php to explicitly prioritize the product post type:
php
CopyEdit
function prioritize_products_in_search($query) {
if (!is_admin() && $query->is_main_query() && $query->is_search) {
$query->set('post_type', ['product', 'page', 'post']);
}
}
add_action('pre_get_posts', 'prioritize_products_in_search');
2. Tweaked Search Ranking
Where relevant, we added meta_query conditions to help highlight results with product-related fields or keywords.
3. Cleaned Up the Layout
We also updated the styling to clearly differentiate product search results from regular posts or pages.
4. Excluded Unwanted Results
Certain pages were excluded altogether based on the client’s request — helping keep the results more relevant and conversion-focused.
The Result
Now, when users search, product pages are displayed first, followed by any relevant blog posts or static pages. No more dead ends or confusing results.
Want your WordPress search to highlight your most important content?
Let Integriti Studio optimize your search experience.
Need help improving your WordPress forms or custom workflows? We build clean, reliable, and growth-driven WordPress solutions—without breaking a sweat.
Let’s Talk