Skip Navigation

[Resolved] Creating a filter removing duplicates on loop using array_unique()

This support ticket is created 5 years, 8 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by SimonR4891 5 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1327849

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

#1327925

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

#1327963

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

#1327965

My issue is resolved now. Thank you!