Results As You Type
What it does
When a visitor types two or more letters into the search box in the header, the mobile menu or the footer, a short list of matches opens under the box. It's grouped by kind in the same order as the search results page: pages first, then each plugin's section (events, people, classes and so on), then products on a WooCommerce store, then posts, then everything else. Each group shows its first three matches and how many there are in all.
- The words the visitor typed are highlighted in each title.
- Pages show the pages they sit under, posts show their date and thumbnail, products show their image and price, and other kinds show their featured image when they have one.
- See all N results at the bottom opens the full search results page.
- The list only shows what the results page shows: posts hidden with Hide From Site Search stay out, and the counts match the page's.
Keyboard and screen readers
Focus stays in the search box. The down and up arrows move through the matches, Enter opens the chosen one, and Enter with nothing chosen opens the full results page, as before. Esc closes the list; a second Esc closes the header search. Screen readers hear how many suggestions there are once the list settles, and each match's title and line as it is chosen.
Things to know
- There's nothing to set up: it works wherever the theme shows a search box (turn the header search on with Show Search in the header's Desktop settings). The search page's own large box doesn't show the list, since the results are right below it.
- If the page can't run scripts, the search box works as it always did.
- The list is fetched fresh for each search, never from the page cache, so a new or changed page appears as soon as it's published. It waits until the visitor pauses typing, and each search costs the site less than opening the results page.
- Nothing extra loads until a visitor clicks into a search box.
- To turn it off for the whole site, go to Optimize → Site Search and check Show results on the search page only. The search boxes then work as they did before.
For plugin developers
A plugin's search section (ds_search_sections) can say how its matches look in the list with an optional compact callable. It gets the post and returns plain text and addresses; the theme escapes the text and highlights the searched words:
$sections['events'] = [
'render' => 'my_events_search_render',
'compact' => static fn(WP_Post $post) => [
'meta' => my_event_date_line($post), // "Mar 4 · Room 101"
'image' => '', // no image; leave the key out to use the featured image
],
];
Keys left out come from the post: title (the post title), url (the permalink), image (the featured image's thumbnail) and meta (none). Without compact, a match shows its title and featured image. The list uses the section's own query, so a section that lists only upcoming events lists only those here too.
Developers can also turn the feature off in code with add_filter( 'ds_search_live', '__return_false' ); (the Optimize setting uses the same filter). The list comes from GET /wp-json/dirigible/v1/search?s=…, which answers only this site's own pages.