Posted on by

Customizing the List Search: Searching on Only One Field

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:

First NameLast NameClub RoleCityStateMain ActivityPhoto
Jim Giray Volunteer Baltimore Maryland
Bob Smith Member
Cavitt Eusebio Volunteer Howey in the Hills Massachusetts
david Ortiz Member
john Bloggs Member
Bob Smith Member
Jonathan Greene Member
Judith Flores Member
Alonzo Byers Member
rlöad Roland Member

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.

14 thoughts on “Customizing the List Search: Searching on Only One Field

  1. Hi!

    Is it possible with that system to allow a search on all fields, without forcing the choice of a specific field in the dropdown list? And if yes, is it possible to allow both systems : Search in all fields or a specific one.

    Thx for your help.

    1. This is possible using the Combo Multisearch add-on.

  2. Just a brief note…
    I was struggling with your search_fields shortcode and eventually worked out that I needed to put the fields in quotes e.g. for the situation / fields that I’m using:
    [pdb_list search_fields="resource_title, resource_notes"]

    1. Yes, any time there are spaces in the attribute value, quotes must be used. I’m sorry that wasn’t made clear.

  3. Hi Roland, great work on the plugin! it has come a long way.
    I want to know if i can do away with the search drop down list but have the search form search multiple fields. like first name and last name concurrently .

    1. You’ll need to get the Combo Multisearch add-on to do that.

      1. can i use the plugin for diff sub domains which is technically extensions of the parent site.?

  4. Hi, I’m still getting this set up, and it seems great. However I have a search problem: When I run a search it gives results. If I have to click to the second or other pages of results, it displays all database results again instead of those that are just search results. Just wondering what is going on here:

    https://growgreatfruitprogram.com/fruit-tree-database/

    Thanks.

    1. Hugh, I just tested, and it looks like it’s working fine. You could be having trouble with your cache. If you’re using any kind of page cache (not browser cache!) you should disable it for your search page.

  5. Thank you. Yes, it is working for me now also. Before I was not getting results. Thank you.

  6. My search function is not working on this page:

    http://www.fsacrylics.com/acrylicpro/

    I am interested in the upgrade to search that you offer but want to see this work first.

    Any ideas?

    1. Hi Jon,

      Can you be more specific? It tested fine for me, but I don’t know what you are expecting.

  7. Thanks – your plugin is fantastic. I am having an issue though – when I use the [pdb_list] I get the results correctly and if I click for the next set of records that also works. However if I include any search code on my page I only get the spinning wheel to the right. My database is also not being sorted by last_name like I have it configured to do or there is something wrong in the database on multiple records though in looking at the records I cannot determine what they are.
    The link is http://clubisland.org/home/?page_id=5810
    Email me private if you need the password to access this page.

    1. Hi David,

      You’re getting a “forbidden” error on the ajax call. Probably a security plugin or perhaps security setting on your site. You can solve this either by turning off AJAX (in the plugin settings under the advanced tab) or a more technical solution involves finding out what security code it getting triggered and setting up an exception so the search and sort can submit successfully. This will affect pagination of the list as well.

      I do see what looks like an alphabetical sort by last name in the list.

Leave a Reply

Your email address will not be published. Required fields are marked *

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.

14 thoughts on “Customizing the List Search: Searching on Only One Field

  1. Hi!

    Is it possible with that system to allow a search on all fields, without forcing the choice of a specific field in the dropdown list? And if yes, is it possible to allow both systems : Search in all fields or a specific one.

    Thx for your help.

    1. This is possible using the Combo Multisearch add-on.

  2. Just a brief note…
    I was struggling with your search_fields shortcode and eventually worked out that I needed to put the fields in quotes e.g. for the situation / fields that I’m using:
    [pdb_list search_fields="resource_title, resource_notes"]

    1. Yes, any time there are spaces in the attribute value, quotes must be used. I’m sorry that wasn’t made clear.

  3. Hi Roland, great work on the plugin! it has come a long way.
    I want to know if i can do away with the search drop down list but have the search form search multiple fields. like first name and last name concurrently .

    1. You’ll need to get the Combo Multisearch add-on to do that.

      1. can i use the plugin for diff sub domains which is technically extensions of the parent site.?

  4. Hi, I’m still getting this set up, and it seems great. However I have a search problem: When I run a search it gives results. If I have to click to the second or other pages of results, it displays all database results again instead of those that are just search results. Just wondering what is going on here:

    https://growgreatfruitprogram.com/fruit-tree-database/

    Thanks.

    1. Hugh, I just tested, and it looks like it’s working fine. You could be having trouble with your cache. If you’re using any kind of page cache (not browser cache!) you should disable it for your search page.

  5. Thank you. Yes, it is working for me now also. Before I was not getting results. Thank you.

  6. My search function is not working on this page:

    http://www.fsacrylics.com/acrylicpro/

    I am interested in the upgrade to search that you offer but want to see this work first.

    Any ideas?

    1. Hi Jon,

      Can you be more specific? It tested fine for me, but I don’t know what you are expecting.

  7. Thanks – your plugin is fantastic. I am having an issue though – when I use the [pdb_list] I get the results correctly and if I click for the next set of records that also works. However if I include any search code on my page I only get the spinning wheel to the right. My database is also not being sorted by last_name like I have it configured to do or there is something wrong in the database on multiple records though in looking at the records I cannot determine what they are.
    The link is http://clubisland.org/home/?page_id=5810
    Email me private if you need the password to access this page.

    1. Hi David,

      You’re getting a “forbidden” error on the ajax call. Probably a security plugin or perhaps security setting on your site. You can solve this either by turning off AJAX (in the plugin settings under the advanced tab) or a more technical solution involves finding out what security code it getting triggered and setting up an exception so the search and sort can submit successfully. This will affect pagination of the list as well.

      I do see what looks like an alphabetical sort by last name in the list.

Leave a Reply

Your email address will not be published. Required fields are marked *

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.