# Show the Number of Search Results

> Prints a line such as 12 results for "pricing" above the search results, so visitors know how much was found.

- Type: PHP
- Runs: Frontend only
- Category: [Search](https://wpide.com/library/category/search/)
- Tags: search, results, count
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/search-results-count-heading/

## Code

```php
add_action( 'loop_start', function ( $query ) {
    static $done = false;

    if ( $done || ! $query->is_main_query() || ! $query->is_search() ) {
        return;
    }

    $done  = true;
    $count = (int) $query->found_posts;
    $label = 1 === $count ? '%1$s result for "%2$s"' : '%1$s results for "%2$s"';

    echo '<p class="wpide-search-count">' . esc_html( sprintf( $label, number_format_i18n( $count ), get_search_query( false ) ) ) . '</p>';
} );
```

## Notes

The line appears where your theme starts the results loop.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show the Number of Search Results" 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/
