How to Prioritize Products in WordPress Search Results

If your site uses custom post types (like “Products”) but they aren’t showing up where they should in search results, you’re not alone. A client came to us with this exact issue — default WordPress search behavior was showing blog posts and pages first, while product pages were buried or missing. Here’s how we fixed it with a clean, logic-first approach.

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

Other Resources Post

Fixing WordPress News Imports & Broken Links

Migrating legacy news posts to WordPress revealed messy data and broken links. With smart import tweaks and custom field logic, we transformed it into a clean, working archive.

Fix Missing UTM Tracking in GA4 & GTM

If your UTM tags show in URLs but not in GA4 reports, you're not alone. At Integriti Studio, we solved a real case where missing campaign data in GTM had a surprisingly simple fix.

Migrate WordPress—retain SEO.

Migrating your WordPress site doesn’t have to risk SEO—done right, it preserves rankings, traffic, and user experience while boosting performance, security, and reliability through
smart tools, and best practices.

Powered by Creativity,
Fueled by Caffeine.

Get Started