Skip Navigation

[Gelöst] Filter dropdown menu populated with multiple values from a comma-separated field

This support ticket is created vor 3 Jahre, 4 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 4 Antworten, has 2 Stimmen.

Last updated by David vor 3 Jahre, 4 Monate.

Assisted by: Waqar.

Author
Artikel
#1869217

I don't suppose it is possible to generate a select menu of options from a single line text field that has comma-separated data? For example, I have one CPT field for the model years supported for a car part. Entered into this field is "2014, 2015, 2016, 2017, 2018". Using this field to create a filter select menu of course renders that entire value into on option like so:

<select>
<option value="" selected="selected">Select Year</option>
<option value="2014, 2015, 2016, 2017, 2018">2014, 2015, 2016, 2017, 2018</option>
</select>

What I'd like to do is have Toolset parse that field and create a select menu from those comma-separated values that is more like:

<select>
<option value="" selected="selected">Select Year</option>
<option value="2014">2014</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
.... and so on.
</select>

I know I can achieve this using a repeater field instead of single line text field like I am, but using a single line text field would technically be a lot easier for data entry. Hope this makes sense.

#1869849

Waqar
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

query-filter-settings.png

Hi,

Thank you for contacting us and I'd be happy to assist.

On my test website, I was able to make this work, using manually filled values in the "wpv-control-postmeta" shortcode in the "Search and Pagination" section:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-control-postmeta )

Example:


<div class="form-group">
	<label for="wpv-wpcf-car-models">[wpml-string context="wpv-views"]Car Models[/wpml-string]</label>
	[wpv-control-postmeta type="select" field="wpcf-car-models" source="custom" url_param="wpv-wpcf-car-models" values=",2014,2015,2016,2017,2018" display_values="select year,2014,2015,2016,2017,2018"]
</div>

And the attached screenshot shows the "Query Filter" settings for this custom field.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1870775

Waqar-

Okay, I see that these are "manually" entered values. I want them to be automatically populated by the vehicles entered into the database. Manually entering them means I have to remember to update this filter every time a new year may come about (either older or newer) as opposed to just entering new vehicles that may incorporate new years. For instance:

Vehicle #1 => Year: 2014, 2015, 2016, 2017 (single-line text field)
Vehicle #2 => Year: 2005, 2006 (single-line text field)
Vehicle #3 => Year: 2016, 2017, 2018, 2019 (single-line text field)

Would automatically yield a front-end select box of:

<select>
    <option value="" selected="selected">Select Year</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2014">2014</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
</select>

No bother, I just went ahead and used a repeater field for now.

#1872769

Waqar
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and for the automatically populated values, the repeater field is the way to go.

You're welcome to mark this ticket as resolved and for a new question or concern start a new ticket.

#1873495

My issue is resolved now. Thank you!

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