Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Fill select box from database
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 6 years, 10 months ago.
- AuthorPosts
- February 3, 2017 at 4:03 pm #11812
Hello,
Is there a way to fill a select box or radio boxes with values from the database? I have a car search and I only want the brands in the field that are available on the website at that moment. Can I use a hook or something to make this?
Thanks,
BarbaraFebruary 7, 2017 at 10:16 am #11832Hi Barbara,
For custom field filters it is actually possible. For each value a filter is executed before output, in the following format:
$values = apply_filters("asp_cf_{filter_type}_values", $values, $item);
So for radio type, it’s like this:
$values = apply_filters("asp_cf_radio_values", $values, $item);
for drop-down like this:
$values = apply_filters("asp_cf_dropdown_values", $values, $item);
In which the $values is an array of [option, value] keypais, like for example:
$values = array( array('option1', 'Label value1'), array('option2', 'Label value2**'), // Double star at the label means, it is selected etc... );
Based on this you can make functions to fill or alter the values array as you like. For example, this function will add additional values to the output, for the filter on the ‘test_field’ custom field:
I hope this helps!
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
February 7, 2017 at 11:11 am #11835Thanks for your reply!
It worked, after I found that there’s a typo in the plugin code in asp.shortcode.custom_fields.php
It says “asp_cf_drowpdown_values” (an extra w).Greetings,
BarbaraFebruary 7, 2017 at 11:12 am #11836Thank you very much Barbara, I will fix that for the upcoming release.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.