Note: it is no longer necessary to use a custom template to control which fields are in the search dropdown. There is an attribute in the list shortcode “search_fields” where you can determine which fields are in the dropdown, so setting it up to search on a single field is as simple as:
With that, the search dropdown won’t be shown and all searches will now take place on the “city” field.
You can also use the attribute to set a list of fields to include in the dropdown.
In some situations, you want your users to find a record by searching on only one field. For example, a property lookup where the users is expected to know the parcel number, or some other situation where you only want users searching on a single field.
This is very easy to implement, you’ll need to create a custom template for your list shortcode. Check this page for the general instructions on how to do that. Use the “pdb-list-detailed.php” template as your starting point.
In that template is a function that produces the field selector dropdown. What you need to do is replace that function with a hidden field that determines the field the user will be searching on.
In the pdb-list-detailed template, you’ll find:
column_selector( false, true, false, 'column' ); ?> ?>
We just need to replace this whole block of code (most of it is just an explanation how to use the $this->column selector method) with our hidden field. Notice that we are no longer inside of the <?php ?> tags, this is straight HTML:
You will replace “your_search_field_name” with the name of the field you want your users to search on. That’s it!
Here is the complete template, demonstrating how to set this up for the “city” field. You can use this template as a starting point if you want.