Hello, I can create filters using the Toolset builder which works great but I am looking at creating a custom filter in PHP which I need duplicate values removing and displaying in a list so they are clickable.
For example this is the development.
hidden link
You will see on the make dropdown there are 3 values ? AUDI , BMW , VAUXHALL which is in a dropdown ? how do I make this into a list <UL><LI> rather than <SELECT> dropdown.
I have tried creating a custom WP query with a loop and putting the field into a string then using array_unique() to echo the results but it doesn't work.
Is this possible within Toolset or is custom code required ?
Thanks
Simon
Hi Simon,
Thank you for contacting us and I'd be happy to assist.
There is no direct shortcode or function to get the raw list of those options, but you can adapt any of these workarounds, based on the requirement.
1. If your goal is only to have that list, so that the filter selection can be triggered on click, you can change the type of filter field from the "select" to "radios". As a result, the options will show in a group of radio buttons. You'll be able to hide the actual radio buttons using the custom CSS code, whereas clicking on the labels would still change the filter.
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-520693 )
Example:
[wpv-control-postmeta field="wpcf-field-slug" url_param="wpv-wpcf-field-slug" default_label="All" type="radios"]
OR
2. If you'd like to get the list of those options in a PHP code, you can create a custom shortcode, that first gets the select field's output/markup and then explodes it into arrays, to generate the list in the desired format, for example an unordered list ( UL and LI tags ).
Here is an example of a very similar custom shortcode:
https://toolset.com/de/forums/topic/title-in-filter-post-reference-field/#post-1197831
OR
3. You can also use custom jQuery script to get the options from the select field and then it can be shown, in the desired format.
( ref: https://stackoverflow.com/questions/590163/how-to-get-all-options-of-a-select-using-jquery )
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks for the quick reply.
Thinking about it, the easiest solution is probably to use Javascript to mirror the SELECT values and output them into an array then into a UL > LI.
I will give this a go.
Regards
Simon
My issue is resolved now. Thank you!