Skip Navigation

[Resolved] How to show relevant taxonomies in a select filter?

This support ticket is created 7 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 21 replies, has 2 voices.

Last updated by Nigel 7 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#407843
Skärmklipp 2016-06-16 11.25.28.png
Skärmklipp 2016-06-16 11.41.50.png

I have a custom post type (Contacts) with a taxonomy called "Countries".
I have set up a Parametric search where I have set up a Query filter to show only contact people with a specific post-id. I've also set up a filter to only use selected countries to search in.
See attached image.

Now when I create my filter (Select with dropdown) I still see all Countries in the list (See attached image). I only want to show the countries that really have those post-id's related, from my Query.

Basically what I want to accomplish is to have a dropdown-list where people can select a country and then get the contact information from a responsible person from that country.

How to do this?

Oh, it's urgent too :-/

#407896

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screen Shot 2016-06-16 at 13.40.09.png
Screen Shot 2016-06-16 at 13.36.04.png

So, you want to be able to filter contacts by country, so that on this contact search page they select a country from a dropdown box and are shown just those contacts for that country.

But you are additionally limiting which contacts are included in the search by specifying their post ids, and you want it so that only the countries relating to this subset of contacts is displayed in the dropdown select.

That last part is problematic. On a parametric search page when you add the filter via the New Filter button in the Filter Editor (see screenshot) it creates the taxonomy filter that works off the select dropdown. Normally you can't see it unless you are displaying all sections or have enabled it via screen options at the top of the page. The generated taxonomy filter is shown in the second screenshot, which also includes a second filter I manually added for the contact posts ids and which does not appear in the parametric search controls.

When you add the taxonomy filter you have the option to hide empty taxonomy terms, but that doesn't help if you have country terms allocated to posts other than your limited list of contacts.

Solutions.

Can you redesign your post types and taxonomies slightly so that, for example, your "country contacts" are a child post of "contacts" and have their own country taxonomy which is not used elsewhere, so that the hide empty option would become meaningful.

The alternative is more of a hack, and involves adding some bespoke JavaScript so that when your country select box is displayed on the front end you use a whitelist (or blacklist) to remove the countries which you want to be excluded.

What solution would work best in your case? Let me know if you need any more help with it.

#408176

Hi Nigel,

Unfortunately I cannot (will be messy) create another child post for those contacts. They are all a part of a contact database with another parametric search activated. So I rather not start messing around with that.

The JavaScript hack you're refering to sounds interesting thought.
Please let me know how to do it.

#408272

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Erik

Sitting down to work out a solution it occurs to me that if you can manually set which countries to include (as per your screenshot) then the answer is not so difficult.

If you look at the documentation for the wpv-control shortcode which generates the select box (https://toolset.com/documentation/views-shortcodes/#wpv-control) you will see that you can set the options and display options as comma separated lists.

You can see the relevant part of my test view below. Note that I had to delete the taxonomy attribute otherwise it would populate the select box with all the countries.

[wpml-string context="wpv-views"]Countries:[/wpml-string] [wpv-control url_param="wpv-country" type="select" taxonomy_order="ASC" taxonomy_orderby="name" hide_empty="true" values=",denmark,spain, france" display_values="Select Country, Denmark, Spain, France"]

It appeared to work for me, can you test and confirm it works for you?

#408307
parametric3.png
parametric2.png
parametric1.png
parametric-layout.png
noresults.png

Nigel,
Nice solution!
The select box now populates the correct countries, BUT it doesn't show me any results upon selection. :-/

FYI: I show my results in another view below the Parametric search view.

#408411

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

contacts.gif
Screen Shot 2016-06-17 at 17.20.33.png
Screen Shot 2016-06-17 at 17.20.21.png

Could you try adding the search box and results together in the same place?

I set up a very simple test site with just a handful of posts and the results updated when I changed the selection. See the attached screengrab.

I've also added screenshots from my View of the filters.

#408771

Hi Nigel,
Showing the results in a different view was not the case. I had set up a filter different than yours.
Now it works, but somehow it ignores the first "empty" selection (the one that are supposed to be for the "Select country"-item.) Instead it shows the first item in the list, in my case it's the contact person for China. I'd rather see an empty result from the beginning, as the starting "comma" suggest below. How?

[wpv-control url_param="wpv-country" type="select" taxonomy_order="ASC" taxonomy_orderby="name" hide_empty="true" values=",china-south, hong-kong-china-south, denmark, estonia, finland, latvia, lithuania, norway, poland, sweden, uk, ukraine" display_values="Select Country, China South, Hong Kong, Denmark, Estonia, Finland, Latvia, Lithuania, Norway, Poland, Sweden, UK, Ukraine"]

Thanks!

#408806

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

That's frustrating, as I used the same in my shortcode and it worked fine.

Can you try putting in an faulty value, e.g. "hogwarts" as the first value, which I would expect to simply return an empty set of results for the initial load.

#409434

Nigel,
Unfortunately it totally ignores the first value. I added "none" just to see what happens.
No luck, still showing the first item :-/

#409679

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Erik,

right now I'm stumped, your shortcode looks the same as mine apart from its length, and I checked that you have the same number of values and display_values, I can't see anything wrong with it.

I have posted a message on our internal board to see if any of my colleagues can think of what might be causing it and will let you know.

#412362

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I'm just following up to see if you managed to get this working?

#415108

Hi Nigel,
Sorry, but no. I still haven't managed to get this to work.
The sites are live now and the client is still on me to remove the first person that shows up.

#415138

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Rats.

Can I get a copy of your site so I can do some testing?

Could you please use one of the following two free plugins to create a snapshot of your site and upload it to a public url (such as dropbox or google drive) so that I can reproduce a copy of your site locally to test. You may want to set up a temporary admin account for me before you do which you can later delete.

* Duplicator. You will need to create and upload both the installer and archive packages as shown in the demo video on their plugin page: https://wordpress.org/plugins/duplicator/. You can omit un-required files such as .log, .zip files etc.

* All-in-One WP Migration. This is simple to use and is less prone to fail because of server settings than Duplicator. https://wordpress.org/plugins/all-in-one-wp-migration/. But note I can only import archives up to 512Mb in size. If they are not relevant to your issue, you can omit media files which will reduce your archive size.

I will mark your next reply as private so that you can give me the url to retrieve the backup files.

Can you also confirm the url of where I can see the problem.

#415339

Sounds great.
Just activate the "Private" message and I'll send you the information. 🙂

#415342

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Sorry, did I not do that?

Here you go.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.