Title: Loading Select Option Programmatically
Last modified: June 28, 2023

---

# Loading Select Option Programmatically

 *  Resolved [thewebtailors](https://wordpress.org/support/users/thewebtailors/)
 * (@thewebtailors)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/loading-select-option-programmatically/)
 * 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](https://wordpress.org/support/users/acowebs/)
 * (@acowebs)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/loading-select-option-programmatically/#post-16856246)
 * You can manage dropdown options using filter `wcpa_form_field` in pro version
 * Find an example below
 *     ```wp-block-code
       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](https://wordpress.org/support/users/thewebtailors/)
 * (@thewebtailors)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/loading-select-option-programmatically/#post-16857458)
 * 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.

 * ![](https://ps.w.org/woo-custom-product-addons/assets/icon-256x256.gif?rev=3328656)
 * [Product Addons for Woocommerce - Product Options with Custom Fields](https://wordpress.org/plugins/woo-custom-product-addons/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-custom-product-addons/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-custom-product-addons/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-custom-product-addons/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-custom-product-addons/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-custom-product-addons/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [thewebtailors](https://wordpress.org/support/users/thewebtailors/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/loading-select-option-programmatically/#post-16857458)
 * Status: resolved