Search

Direct Query Search

Direct query search is useful when you already have a form or URL parameter and only want the query loop to read it.

Read From GET#

Use a single-brace value in the query attribute:

phpresources/views/search.php
<form method="get">  <input type="search" name="q" value="{{ get:q }}" placeholder="Search">  <button>Search</button></form>{{ query:posts search="{get:q}" search:in="title|content" }}  <h2><a href="{{ url }}">{{ title }}</a></h2>{{ /query:posts }}

The form is plain HTML. The query reads q from the URL.

Search Areas#

Use search:in to choose what WordPress searches:

php
{{ query:posts search="{get:q}" search:in="title|content|excerpt" }}

Supported areas are title, content, and excerpt.

When To Use This#

Use direct query search when the search form already exists, or when the query should respond to a URL value created somewhere else.

Use {{ search }} when you want TemplateX to connect the form and query for you.