Posted on by

Creating Links to Show a Filtered List Result

This post is about how to construct a link that when followed, shows a specific search result in the Participants Database list display.

So, first of all you need to set up your base URL. This is the URL that takes you to the page that shows the [pdb_list] shortcode.

In the following examples, you would add the ? and everything after that to your base URL to get the URL to use on your site.

Important: if your base URL has a ? in it, then to use the examples, replace the ? in the example with a & so that the variables will be added to the variable that is already in your base URL.

For Example

Let’s say you have a list of people who have specific skills. They’ve filled in their information using a “multiselect” to indicate which skills they have. Now, you want to show a link on your site that will show all the people with a particular skill.

This is easy to do, because it’s possible to include simple search parameters in a URL to a page with the [pdb_list] shortcode.

Let’s say the name of your skills field is “skills” and you want to show all the web designers. First, take a look at the values you have defined for your Skills multiselect so you know the exact string to look for. In this case, it’s ‘web designer’. The case is not important.

In a URL, the search parameters are ‘search_field’ and ‘value’ so we tell the list which value we are seeking in which field. Now, our search term has a space in it, so because we are using the term in a URL, we need to convert that space into a URL-encoded value. The value for a space is %20, so this will be what you will add to the URL for the search result page:

?search_field=skills&value=web%20designer

And that will show you all the people who checked “Web Designer” in their skills.

You can only do simple searches this way: on a single field with a single search term. If you want something more complex than that, you’ll need to create a custom WordPress template that can process a more complex search from the URL and build those into the filter attribute of the list shortcode.

Wildcards

You can use the wildcard characters (*?) in the search value. For instance, if you want the URL to match just the first letter, you could set up a URL like this:

?search_field=last_name&value=a*

That will show all the records with a last name that begins with “a”.

Advanced Use: Operators

If you need to tweak the results some, you can use an “operator” to change how the search is performed. If an operator is not specified, it defaults to matching the record if the serch term is found within the field data. If you need it to show only exact matches, you can add an operator to the URL, like this:

?search_field=thing&value=car&operator=eq

That will match only a thing value of “car” and not something like “cart” (Note: you can’t use wildcards with the “eq” operator.)

Other operators you can use are:

codeoperator
eqequals
~like (find within the data)
gtgreater than
ltless than
nenot equals

Links like these will work with the Multi-Search feature of the Combo Multisearch add-on. Note that this only works with fields that are configured in the Multisearch section of the add-on, also operators in the URL won’t change how the search works. This is because the URL is simply preselecting the multi-search fields and submitting the search.

It’s also possible to create a URL that filters on multiple fields with a syntax like this:

?search_field[]=city&value[]=Huntsville&search_field[]=state&value[]=al

Note the brackets which allow multiple values for “search_field” and “value.” In order for this to work, the “search_field” value must be paired with a “value” value and in the same order.

Sorting The List

It is also possible to set the sort of the list in the URL. The variable names to use for that are ‘sortBy’ and ‘ascdesc’ which should hold the field name and the direction of the sort, respectively. For example, to sort by last name in normal alphabetical order, you’d use a URL with variables like this:

?sortBy=last_name&ascdesc=asc

Of course, this can be combined with sort terms by using the & symbol…for example:

?search_field=last_name&value=a*&sortby=last_name&ascdesc=asc

61 thoughts on “Creating Links to Show a Filtered List Result

  1. Hi Roland, the paging (1, 2, 3 …) on the search results somehow doesn’t carry over the ?search_field and other variables and only have the ?listpage and instance so all the subsequent pages would show the whole list. I must have missed something.

    Thanks for your help.

    1. This normally works, so maybe your sessions are not working. Do you have a link so I can see it?

Leave a Reply
You have to agree to the comment policy.

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

61 thoughts on “Creating Links to Show a Filtered List Result

  1. Hi Roland, the paging (1, 2, 3 …) on the search results somehow doesn’t carry over the ?search_field and other variables and only have the ?listpage and instance so all the subsequent pages would show the whole list. I must have missed something.

    Thanks for your help.

    1. This normally works, so maybe your sessions are not working. Do you have a link so I can see it?

Leave a Reply
You have to agree to the comment policy.

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