Skip to content

WordPress Search Templates: Test the No Results Block

Add a retry form to a WordPress block theme and test when it appears. See how the same template handles a known match and an empty search.

Two paper search layouts showing result rows and a lavender fallback panel
Jack Lee
3 Min Read
Share
On This Page

A visitor searches your WordPress site for “ceiling fan.” One lesson appears. They search for a term that matches nothing and get a blank list. In a block theme, you can put a helpful message and another search field inside the Query Loop’s No Results block.

Find the branch in the Search template

Open the Search template in the Site Editor and use List View to inspect its Query Loop. In the loop’s settings, use Query Type → Default so it inherits the template query. That lets WordPress use the visitor’s search term. A custom loop showing recent posts can appear full even when the visitor’s search has no matches.

Inside that Query Loop, keep Post Template for the matched items and No Results as its sibling. Put the fallback paragraph and Search block inside No Results. If the message is below the Query Loop at the template’s top level, WordPress can show it even alongside real matches.

Test a hit and a miss

I ran both requests against the same small WordPress 6.9 block theme with one published lesson called “Ceiling fan maintenance.” I set the Query Loop to inherit the search query and placed a retry form inside No Results.

QueryResults in the loopEmpty-state messageRetry form in the loop
ceiling fanCeiling fan maintenanceHiddenHidden
zzsearchfixturezzNoneNo lessons match. Try a shorter term.Visible

Both responses returned HTTP 200. For this test, the useful checks are the returned title, the message and the retry form. A successful response by itself tells you nothing about which branch rendered.

If the wrong branch appears

  1. Both searches show the same posts. Check whether the Query Loop inherits the search query and whether a search plugin changes the results.
  2. Matches and the fallback appear together. In List View, check whether the message sits outside No Results or in a second loop.
  3. A known post still shows the fallback. Search for a short phrase from the title of a public, published item. Verify that you’re editing the search template the active theme actually uses.

On a staging site, repeat both searches while signed out. At mobile width, check that you can focus the retry field, type a new term and submit it. Also try a term with more results than fit on one page if your site uses Query Loop pagination. Keep the separate decision about whether internal search URLs should be indexed out of the template test.

Frequently asked questions

Where should I put the retry search box?

Place it inside No Results if it should appear only on an empty result. Put a search box outside the loop if you want visitors to see it on every results page.

Why do unrelated posts appear for a nonsense term?

Check whether the Query Loop is running its own query. If it inherits the search query, inspect any search plugin that changes what counts as a match.

How do I know the empty state works?

A known search shows the expected post without the fallback, and a deliberate miss shows the fallback and the fields you placed inside it. Check both on the public-facing template.

Share This Article