Skip to main content
Documentation/Templating/Search Templates
Templating

Search Templates

A search template designs the results page visitors land on after using a search form.
It works like an archive template — a query of
results rather than a single item — with two additions: the search term itself is
available as dynamic data, and you can target templates at the term or at the number of
results found.

Creating a search template

  1. In wp-admin, go to Oxygen → Templates and click Add Template.
  2. Oxygen shows a short warning about reading the documentation before creating custom
    templates — click Continue.
  3. Give it a Title and set Location to Search Results, in the Other group
    of the dropdown.
  4. Click Add template.
The Add template dialog with Location set to Search Results

The template starts empty. Click its name in the list to open it in the builder.

Location

Search Results lives in the Other group of the
Location dropdown. It matches any
request WordPress treats as a search, including a search that returned nothing and
paginated result pages.

Nothing else competes for search requests, so a single search template needs no priority
set at all — see Priority if you build a second one.

Displaying results

Results are rendered by a Post Loop Builder, exactly as on
an archive: add one and leave its query untouched, and a loop with no query of its own
inherits the page's main WordPress query — which on a search request is the search itself.
The loop element in full is covered in Loops.

A search results page on the front end: the heading showing the term, the loop rendering the matches below it

Worth knowing: WordPress search spans post types, so the inherited results can include
pages and custom post type items alongside posts. A search for a term appearing in a
page's title returns that page. If you want results restricted to one post type, that's
a case for applying a query to the loop rather than inheriting.

Dynamic Data

The search term itself is available as a field, Search Query. Bind it into a heading
and you get the usual "Search results for: term" line, filled in per search. It's a plain
string, so prepend and append text work around it.

Binding controls to data is dynamic data; every
field is listed in the Fields Reference.

A heading in a search template bound to the Search Query field

Designing the empty results case

A search that finds nothing renders an empty list. To give it something better, target a
second template at the same Location with the condition WP_Query Found Posts Count is
less than 1
— the "no results" condition. When a search comes back empty that template
wins and renders your message instead.

One more condition exists only here: Search compares the actual search term with is
and is not, which is how a heavily-searched term gets its own curated landing design.
Both are catalogued in
Conditions Reference, and the empty-results
condition works the same way on archives.

The empty-search page a visitor gets when a search finds nothing

Previewing

Search templates are previewable in the builder — Oxygen offers a search preview so the
canvas has real results to render while you design. The 404 location is the exception;
see 404 Templates.