Return to Add or Edit a Query
In addition to retrieving and displaying content, you can also enable users to find specific content by adding search forms to your queries.
Search forms can be added to any query, and can contain any number of search fields. A basic search form might just have a text field and a submit button. A complex form for an “Advanced Search” page might have multiple text fields, dropdown menus, and checkboxes.
For example, let’s say you want to create a search form for a “Books” database. Books have fields called “title” and “synopsis”; a taxonomy called “genre”, and are connected to another content type called “Authors”.
Here are some potential fields your search form could have:
- A text field that searches within all titles and synopses
- A text field that only searches titles
- A dropdown that can narrow results to a specific genre
- A checklist that can narrow results to multiple genres
- A text field that returns all books by the specified author
To add a search form, the option “Include a search form” must be selected in the query’s Settings tab. Once it is, a “Form” tab will appear with two boxes: “Form Fields” and “Form Options”.
At the top of the form tab is a large box labeled “Fields” which is used to add and remove form fields.
This box behaves similarly to the way you add fields to a content type via Creator > Fields:
- Each row represents a new form field.
- New fields can be added via the “Add Field” button at the bottom.
- Fields can be reordered by clicking and dragging the icon in the “Sort” column.
- Fields can be deleted by clicking the trash icon in the “Delete” column.
For each field, you will enter the following information:
The optional text label for the field.
The types available will depend on the content type being queried. Potential options include:
Search all fields
This creates a text field that searches within all of the content type’s fields, plus the basic WordPress title, content, and excerpt fields.
There are two notable exceptions: “Search all fields” does not search in taxonomy and connection fields, which are considered special fields and have their own search abilities.
Search specific field
This heading lists available fields underneath. Select one to create a text field that only searches within the selected field.
Filter by taxonomy terms
This heading lists available taxonomies underneath. Select one to create a list of terms from that taxonomy.
Using the options column (see below), this list can be displayed as a dropdown menu, checklist, or radio button list.
When a user selects one or more terms, the results will only be returned from those particular terms. A simple example would be a “Book” search form in which users can select a specific “Genre” from a dropdown menu.
Search in connection
This heading lists available connection types underneath. Select one to create a field that searches inside those connections.
Connection searches are more complicated because you need to specify in the options column (see below) what, inside the connection, you wish to search — the connection’s fields, taxonomies, etc.
This is also quite powerful. Using the Book search as an example, if the connected “Authors” content type had a taxonomy called “Home Country”, you could add a field that filtered all books by authors from a specific country.
This creates a single checkbox, which can be checked to only return results that satisfy a particular condition. This condition can be related to a field or a taxonomy.
For example, users could check the box to only return results with:
- A file uploaded
- A star rating of 4 or 5
- A “suitable for children” field set as true
- A price less than $1,000
Depending on what was chosen for the Search Type, additional options will appear in this column. All possible options are listed below; click a link below to jump to the option’s description and an explanation of when they appear:
- Default Option
- Order By
- Inner Search Type
- Checkbox Options
- Condition Type
- System Name
Available for basic text fields. Text entered here will appear within the text field. Once a user begins typing in the field, the text will disappear. If the user clears the field, the placeholder text will re-appear.
Available for taxonomy fields. Display has four options: “Dropdown”, “Multi-Select Dropdown”, “Checklist”, or “Radio Buttons”.
Available whenever “Dropdown” is selected as the “Display” option. Text entered here will appear as the first, top option of the dropdown.
Available for taxonomy fields and certain connection fields. For taxonomy fields, this includes the following options:
- Name – list terms alphabetically by name.
- Popularity – list terms by the amount of content related to each term
- Term ID – list terms according to their internal ID number. This will be the order the terms were first added.
- Slug – list terms according to their “slug”, or URL-friendly name.
For connection fields regarding a content type, it includes the following options:
- Date published
- Date modified
- Menu order – if the content type has the “sub-pages and ordering” feature turned on, this refers to the “order” option.
- Slug – the post’s lowercase-no-spaces title used in permalinks.
- ID – a unique number, assigned to the content when it is first added.
- Custom field – when this is chosen, an “Enter field name” option will appear where you can enter the custom field key.
- Existing fields – beneath the above options, any fields assigned to this content type will also be listed. (Taxonomy, connection, and instruction fields are not included.)
For connection fields regarding users, it includes the following options:
- Display name
- Email address
- Date registered
- Authored Posts – the total number of posts on your site of which the user is set as the author.
- ID (order added) – a unique number, assigned to the user when the user is first registered.
Available for taxonomy fields and certain connection fields. This allows you to control whether your choice in the “Order By” dropdown will be ordered low-to-high (“Ascending”) or high-to-low (“Descending”).
Inner Search Type
Available for connection searches. This dropdown mimics the “Search Type” dropdown, but contains information related to the connection. It allows you to choose what should be searched within that connection.
For example, echoing the Book Search example used above, if this field is set to search within “Authors” connected to Books, you could select whether to search within all Author fields, specific Author fields, specific Author taxonomies, or even other Author connections.
Once a selection is made, the options below will change to reflect options available to that search type. For example, if you select the Author’s taxonomy “Home Country”, you will see Display, Order By, and Order options below.
The special case is when you select an inner connection. Let’s say Authors has another content type connected to it, called Literary Agents. At this point, there are three content types in play:
- Books, which are connected to
- Authors, which are connected to
- Literary Agents.
These types of fields will be outputted as a list of the third content type’s titles, and will have Display, Order By, and Order options.
You cannot go any further than three levels deep.
Available for “Toggle condition” fields. All condition fields display as a checkbox, so this contains two basic options about the checkbox:
- Check the box marked “set as checked by default” to force the box to be checked when the form is first displayed.
- Enter text in the box marked “Checkbox text” to add labeling text to the direct right of the checkbox.
Available for “Toggle condition” fields. This sets up the condition that is being checked. It is a dropdown menu with two options: “Field” or “Taxonomy”. If the condition should check against the value of a field, select “Field”; if it should check against taxonomy terms, select “Taxonomy”.
Available for “Toggle condition” fields. This is a set of options that only appears after a “Condition Type” has been selected.
If “Field” was selected as the condition type, the following options appear:
- A text box labeled “Field Name” that accepts the system name of a field.
- A dropdown containing the following comparison operators:
- Equal To
- Not Equal To
- Greater Than
- Less Than
- Greater Than or Equal To
- Less Than or Equal To
- Not Like
- Field Exists (no value needed)
- Field Doesn’t Exist (no value needed)
- A text box labeled “Field Value” that accepts the value of the field.
With these three options, we can build the field condition. For example, to build a condition to only return results that have a field called “price” that is set to less than one thousand dollars, you would enter:
- Less Than
The “Like” and “Not Like” operators check to see if fields contain what is specified in the “Field Value” box. For example, to build a condition that only returns books that do not include the word “violent” in their synopses, you would enter:
- Not Like
If “Taxonomy” was selected as the Condition Type, the following options appear:
- A dropdown menu listing available taxonomies. (Only after a taxonomy is selected will the options below appear.)
- A dropdown containing the following comparison operators:
- Includes any of…
- Includes all of…
- Does not include…
- A multi-select box containing all terms in the selected taxonomy. Click inside the box to view the terms and select one or more.
With these three options, we can build the taxonomy condition. For example, to only return Books in either of two specific genres, you would enter:
- Includes any of…
- “Sci-Fi” and “Fantasy”
Note the difference between “any” and “all”. By choosing “Includes any of…” you return books that are either marked Sci-Fi or Fantasy. By choosing “Includes all of…”, only books that are marked both Sci-Fi and Fantasy would be returned. (And likewise, note that if only one term is selected, there is no difference between “any” and “all”.)
Available for every type. This is the “URL-friendly” name for each field. This will automatically generated based on the field label. If no label is specified, enter an identifying phrase for the field here. Only lowercase characters and underscores should be used.
Available for every type. This is the text box labeled “Enter additional notes or instructions here.” Any text added to this box will appear directly beneath each field.
Below the “Form Fields” box is the “Form Options” box, which contains additional options related to the search form as a whole:
The text that appears on the submit button. If left blank, the submit button will say “Search”.
Alternatively, you can enter a full URL pointing to an image file here. If you do, the submit button will be replaced by the image.
Submit button classes
CSS classes that will be added to the submit button. Separate multiple classes with spaces.
Note: this can be particularly helpful if your site is using an HTML framework. For example, Bootstrap users should add the class “btn”, while Foundation users should add the class “button”.
CSS classes that will be added to the <form> tag. Separate multiple classes with spaces.
Arbitrary HTML that will appear directly before the form.
Before each field
Arbitrary HTML that will appear before each form field.
After each field
Arbitrary HTML that will appear after each form field.
Arbitrary HTML that will appear directly after the form.