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

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

  1. I have the exact same issue! I tried turning off AJAX thingy, tried turning on alternative session method, use pagination scroll anchors, nothing works. The pagination links at the bottom simply don’t contain the passed search_field and value parameters. In the upper-right menu are the links to filtered pages.

    1. Can you provide a link to see the problem on your site?

      1. I did and am trying but every time your site tells me my comment looks like spam? (Nice feature btw)
        kamp.byethost10.com

        1. I’m sorry about the spam blocker, I need to dial that back. I suggest you turn the AJAX back on. If that is not working, you may have a problem with an accelerator plugin that is not adding the javascript properly. Also make sure you do not have page caching on. I’ll check it again after you have the AJAX back on.

  2. Hi Roland,

    Is it possible to construct a search-link searching for two or three values within one field?

    Example (using your demo link) searching for both “Huntsville” and “Amsterdam” within the field “city”

    ?search_field[]=city&value[]=Huntsville , Amsterdam&search_field[]=state&value[]=al
    (I use the , comma between the two values, this does not work)

    Thanks!

    Regards,
    Michel Cornelis

    1. Yes, this is possible. This is explained in the article under “Using Filter Links with Multi-Search” you add multiple variables with the same name that includes the brackets, each one of those variables is added to the array. You must also add one field_name[] variable for each value[] variable. Check out the example in the article.

      1. Thanks Roland,
        Obviously I’m doing something wrong, but I do not know what I’m doing wrong

        ?search_field[]=gedichten&value[]=gedichten%20schrijven&search_field[]=gedichten&value[]=beeldgedichten&sortBy=stad_of_gemeente&ascdesc=asc gives met only the values for gedichten>gedichten%20schrijven. The second search in field “gedichten” (gedichten>beeldgedichten) does not give any results.

        When I turn the two values for field “gedichten” around :
        ?search_field[]=gedichten&value[]=beeldgedichten &search_field[]=gedichten&value[]=gedichten%20schrijven&sortBy=stad_of_gemeente&ascdesc=asc

        it shows only the results for gedichten>beeldgedichten, the results for gedichten>gedichten%20schrijven. is not shown. The searchlink only looks to the first field>value combination. What am I doing wrong?

        Thanks,
        Regards,
        Michel Cornelis

        1. To interpret the results, I suggest you turn plugin debugging on (plugin settings under the advanced tab) then clear the debugging log (plugin admin menu) then try your search. The query that was used will be in the debugging log, and that will explain the results.

      2. As you suggested I turned debugging on and it looks like there might be a bug in the plugin. See the results here:
        Searchlink structure: ?search_field[]=field1&value[]=value1&search_field[]=field2&value[]=value2

        1)
        Field1 = gedichten, Value1 = limerick
        Field2 = verhalen, Value2 = kinderverhalen
        Result from debugging:
        [03/15/21 7:33pm UTC]PDb_List::_setup_iteration list query: SELECT p.id, p.voornaam, p.achternaam, p.stad_of_gemeente, p.beroep, p.activiteit_1, p.activiteit_2, p.persoonlijke_foto, p.meer_informatie FROM fzj_participants_database p WHERE (p.gedichten LIKE ‘%”limerick”%’ OR p.verhalen LIKE ‘%”kinderverhalen”%’) ORDER BY p.date_updated DESC
        2 different fields, works fine, no problem.

        <>

      3. Continuation from previous comment

        2)
        Field1 = gedichten, Value1 = limerick
        Field2 = gedichten, Value2 = beeldgedichten
        Result from debugging:
        [03/15/21 7:39pm UTC]PDb_List::_setup_iteration list query: SELECT p.id, p.voornaam, p.achternaam, p.stad_of_gemeente, p.beroep, p.activiteit_1, p.activiteit_2, p.persoonlijke_foto, p.meer_informatie FROM fzj_participants_database p WHERE (p.gedichten LIKE ‘%”beeldgedichten”%’) ORDER BY p.date_updated DESC
        Twice the same field, first field-value combination is not present.

        3)
        Field1 = gedichten, Value1 = beeldgedichten
        Field2 = gedichten, Value2 = limerick
        This is the same as in 2) but the two values are turned around
        Result from debugging:
        [03/15/21 7:46pm UTC]PDb_List::_setup_iteration list query: SELECT p.id, p.voornaam, p.achternaam, p.stad_of_gemeente, p.beroep, p.activiteit_1, p.activiteit_2, p.persoonlijke_foto, p.meer_informatie FROM fzj_participants_database p WHERE (p.gedichten LIKE ‘%”limerick”%’) ORDER BY p.date_updated DESC
        Twice the same field, first field-value combination is not present again. This missing combination was present in example 2) being the last of the two.

        Please advise how to proceed, Thanks

        1. Yes, you cannot use this technique to add two terms to the same field, it does have its limits.

        2. I do plan to make it possible to add multiple terms to the same field in the next update.

  3. 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.

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

  1. I have the exact same issue! I tried turning off AJAX thingy, tried turning on alternative session method, use pagination scroll anchors, nothing works. The pagination links at the bottom simply don’t contain the passed search_field and value parameters. In the upper-right menu are the links to filtered pages.

    1. Can you provide a link to see the problem on your site?

      1. I did and am trying but every time your site tells me my comment looks like spam? (Nice feature btw)
        kamp.byethost10.com

        1. I’m sorry about the spam blocker, I need to dial that back. I suggest you turn the AJAX back on. If that is not working, you may have a problem with an accelerator plugin that is not adding the javascript properly. Also make sure you do not have page caching on. I’ll check it again after you have the AJAX back on.

  2. Hi Roland,

    Is it possible to construct a search-link searching for two or three values within one field?

    Example (using your demo link) searching for both “Huntsville” and “Amsterdam” within the field “city”

    ?search_field[]=city&value[]=Huntsville , Amsterdam&search_field[]=state&value[]=al
    (I use the , comma between the two values, this does not work)

    Thanks!

    Regards,
    Michel Cornelis

    1. Yes, this is possible. This is explained in the article under “Using Filter Links with Multi-Search” you add multiple variables with the same name that includes the brackets, each one of those variables is added to the array. You must also add one field_name[] variable for each value[] variable. Check out the example in the article.

      1. Thanks Roland,
        Obviously I’m doing something wrong, but I do not know what I’m doing wrong

        ?search_field[]=gedichten&value[]=gedichten%20schrijven&search_field[]=gedichten&value[]=beeldgedichten&sortBy=stad_of_gemeente&ascdesc=asc gives met only the values for gedichten>gedichten%20schrijven. The second search in field “gedichten” (gedichten>beeldgedichten) does not give any results.

        When I turn the two values for field “gedichten” around :
        ?search_field[]=gedichten&value[]=beeldgedichten &search_field[]=gedichten&value[]=gedichten%20schrijven&sortBy=stad_of_gemeente&ascdesc=asc

        it shows only the results for gedichten>beeldgedichten, the results for gedichten>gedichten%20schrijven. is not shown. The searchlink only looks to the first field>value combination. What am I doing wrong?

        Thanks,
        Regards,
        Michel Cornelis

        1. To interpret the results, I suggest you turn plugin debugging on (plugin settings under the advanced tab) then clear the debugging log (plugin admin menu) then try your search. The query that was used will be in the debugging log, and that will explain the results.

      2. As you suggested I turned debugging on and it looks like there might be a bug in the plugin. See the results here:
        Searchlink structure: ?search_field[]=field1&value[]=value1&search_field[]=field2&value[]=value2

        1)
        Field1 = gedichten, Value1 = limerick
        Field2 = verhalen, Value2 = kinderverhalen
        Result from debugging:
        [03/15/21 7:33pm UTC]PDb_List::_setup_iteration list query: SELECT p.id, p.voornaam, p.achternaam, p.stad_of_gemeente, p.beroep, p.activiteit_1, p.activiteit_2, p.persoonlijke_foto, p.meer_informatie FROM fzj_participants_database p WHERE (p.gedichten LIKE ‘%”limerick”%’ OR p.verhalen LIKE ‘%”kinderverhalen”%’) ORDER BY p.date_updated DESC
        2 different fields, works fine, no problem.

        <>

      3. Continuation from previous comment

        2)
        Field1 = gedichten, Value1 = limerick
        Field2 = gedichten, Value2 = beeldgedichten
        Result from debugging:
        [03/15/21 7:39pm UTC]PDb_List::_setup_iteration list query: SELECT p.id, p.voornaam, p.achternaam, p.stad_of_gemeente, p.beroep, p.activiteit_1, p.activiteit_2, p.persoonlijke_foto, p.meer_informatie FROM fzj_participants_database p WHERE (p.gedichten LIKE ‘%”beeldgedichten”%’) ORDER BY p.date_updated DESC
        Twice the same field, first field-value combination is not present.

        3)
        Field1 = gedichten, Value1 = beeldgedichten
        Field2 = gedichten, Value2 = limerick
        This is the same as in 2) but the two values are turned around
        Result from debugging:
        [03/15/21 7:46pm UTC]PDb_List::_setup_iteration list query: SELECT p.id, p.voornaam, p.achternaam, p.stad_of_gemeente, p.beroep, p.activiteit_1, p.activiteit_2, p.persoonlijke_foto, p.meer_informatie FROM fzj_participants_database p WHERE (p.gedichten LIKE ‘%”limerick”%’) ORDER BY p.date_updated DESC
        Twice the same field, first field-value combination is not present again. This missing combination was present in example 2) being the last of the two.

        Please advise how to proceed, Thanks

        1. Yes, you cannot use this technique to add two terms to the same field, it does have its limits.

        2. I do plan to make it possible to add multiple terms to the same field in the next update.

  3. 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.