# Match Product Searches on Titles Only

> Makes product searches look only at product names instead of full descriptions, giving shorter and more relevant results for catalogues with long descriptions.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, search, relevance
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-product-search-titles-only/

## Code

```php
add_filter( 'posts_search', function ( $search, $query ) {
    global $wpdb;

    if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() || 'product' !== $query->get( 'post_type' ) ) {
        return $search;
    }

    $terms = (array) $query->get( 'search_terms' );

    if ( ! $terms ) {
        return $search;
    }

    $clauses = array();

    foreach ( $terms as $term ) {
        $clauses[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", '%' . $wpdb->esc_like( $term ) . '%' );
    }

    return ' AND (' . implode( ' AND ', $clauses ) . ') ';
}, 20, 2 );
```

## Notes

Only product searches on the front end are affected; blog searches keep matching content.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Match Product Searches on Titles Only" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
