Fill select box from database

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 Ernest Marcinko 5 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #11812
    Barbara
    Barbara
    Participant

    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,
    Barbara

    #11832
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi 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 :)


    #11835
    Barbara
    Barbara
    Participant

    Thanks 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,
    Barbara

    #11836
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank 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 :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.