Search

Search

Search lets a TemplateX view collect a keyword and pass it into a query loop without turning your markup into WordPress form code.

Put a {{ search }} form before the query it should control:

phpresources/views/front-page.php
{{ search }}  <input type="search" placeholder="Search posts">  <button>Search</button>{{ /search }}{{ query:posts search }}  <article>    <h2><a href="{{ url }}">{{ title }}</a></h2>  </article>{{ /query:posts }}

The search form reads the keyword from the URL. The query loop uses that keyword when it asks WordPress for posts.

Defaults#

By default, {{ search }}:

  • creates a GET form
  • uses the URL parameter q
  • searches post titles
  • fills the input with the current search value