• Resolved thewebtailors

    (@thewebtailors)


    I was about to purchase the premium version of your plugin but I want to make sure this can be done:

    I would like to have a select field that shows a dropdown of schools. These schools are being fed in from a custom post type as there constantly new schools being added and there are hundreds of them.

    Instead of manually entering each school and trying to keep it up to date, is there a filter I can hook into (by e.g. using add_filter) which allows me to load custom options?

    While not a must, it would be even cooler if there would be a dropdown feature like select2 with search and possible ajax support.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author acowebs

    (@acowebs)

    You can manage dropdown options using filter wcpa_form_field in pro version

    Find an example below

    add_filter('wcpa_form_field', function ($field, $productId) {
    
        if ($field->elementId == 'select_0257240251') { // change field id
            $posts = get_posts([
                'post_type' => 'school_post_type',//change post type
                'post_status' => 'publish',
                'numberposts' => -1
            ]);
    
            $options = [];
            foreach ( $posts as $post ) {
                $options[] = (object)[
                    'label' => $post->post_title,
                    'value' => $post->post_name,
                    'selected' => false
                ];
            }
    
            $field->values = $options;
        }
    
        return $field;
    }, 10, 2);

    For premium version support, You can reach us on our website

    Thread Starter thewebtailors

    (@thewebtailors)

    Excellent! Thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loading Select Option Programmatically’ is closed to new replies.