Using the Search Shortcode

The Participants Database Search Shortcode provides a way to show a database search control that is detached from the list of results.

For most applications, the search shortcode is not needed: most of the time, you’ll want the search control to appear directly above the list of results, and for that you don’t need the search shortcode. The search control is set up in the List shortcode like this: [pdb_list search=true]

Only if you want to put the search control in another location, or on another page, would you need to use the Search shortcode. It is also possible to do both: you may have a search control in another location, and also have another search control just above the list of results.

Configuring the Search Shortcode

Use of the Search shortcode also requires a separate target List shortcode in order to display the results of the search.

Putting the Search Control on Another Page

If you want the search control to be on a different page from the search resuts page (or on several pages, such as in a sidebar), you need to tell it which page the list of results (the [pdb_list] shortcode) is on. You do this using the “target_page” attribute in the shortcode. Put the page slug (or ID) into the shortcode like this:

[pdb_search target_page=search-results]

Now, submitting the search will take the user to the “search-results” page to show them the results. Remember, you can prevent the list from showing anything until a search is made by using the “suppress” attribute.

The list showing the results may also have it’s own search control in the normal way. This gives users a chance to modify their search on that page if they want.

Targeting the Result List

To get the shortcode working correctly, you may need to set the “target instance” attribute in the shortcode. Each Participants Database shortcode on a page has a unique instance number. The search shortcode needs to know the instance number of the list where the search results are to be displayed.

To find the correct instance number for your target list, you must look at the HTML of the page where your list of results is shown. At the top of the main container that wraps the list, you’ll find the instance number…for instance using the browser developer’s tools element inspector and selecting the list, you will see something like this:

(If you’re not sure how to see the HTML, read this: Accessing Your Browser Developer Tools)

That indicates that the instance number of the list is “1” so if you wanted the list of results to appear in that list, you’d set up your search shortcode like this:

[pdb_search target_instance=1]

If your search control is on the same page (such as in a sidebar or column) you’re done: submitting a search will refresh the target list on the same page with the results of the search.

Important: if you have a search shortcode and a list shortcode on the same page, you need to have both shortcodes active on the page before you find the instance number of the list.

Determining Which Fields are Searched

You can set up the search shortcode to only search a specific field by using the “search_fields” attribute. Let’s say you want your user to be able to type in the name of a city and show all the results for that city. You’d do that with a shortcode like this:

[pdb_search search_fields=city]

Now, when they type in the name of a city and hit the button, they will be taken to the list of records that match the city they typed in.

If you’re looking for a more full-featured search, check out the Participants Database Combo Multisearch add-on.