# Dynamically Populating Drop Down Fields

**URL:** <https://community.gravityforms.com/t/dynamically-populating-drop-down-fields/1683>\
**Category:** Get Help\
**Tags:** acf, dynamic-population\
**Created:** [April 24, 2019, 2:38pm UTC](https://community.gravityforms.com/t/dynamically-populating-drop-down-fields/1683 "2019-04-24T14:38:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![webmgt](https://avatars.discourse-cdn.com/v4/letter/w/77aa72/32.png) [@webmgt](https://community.gravityforms.com/u/webmgt)\
**Post date:** [April 24, 2019, 2:38pm UTC](https://community.gravityforms.com/t/dynamically-populating-drop-down-fields/1683/1 "2019-04-24T14:38:43Z")

</div>

Hi folks,  
I’m looking for a little bit of help with regards populating a drop down field that is within a custom post type.

I can do this with custom post types & taxonomies however I’m stuck with trying to populate with a sub field (ACF)

Here is what I have.  
I have a custom post type called ‘advanced\_course’  
I have an ACF repeater field ‘pt\_subject\_courses’  
The ACF sub field is ‘pt\_subject\_course\_title’

I’m looking to populate a dropdown field on gravity forms with what ever is in the '‘pt\_subject\_course\_title’ sub field of the repeater field ‘pt\_subject\_courses’

Could anyone direct me to any existing code snippet or give me a shove in the right direction, I’m not looking for another plugin to do this if possible.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![Parkbum](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/parkbum/32/810_2.png) [@Parkbum](https://community.gravityforms.com/u/Parkbum)\
**Post date:** [April 24, 2019, 3:20pm UTC](https://community.gravityforms.com/t/dynamically-populating-drop-down-fields/1683/2 "2019-04-24T15:20:39Z")

</div>

Matters on how the data is being stored. i.e. if you were going to retrieve just one entry, how would you do it? Usually it is something like…

```auto
$args = array(
    'post_type' => 'advanced_course',
    'areas' => 'pt_subject_courses',
    'order' => 'ASC'
    );              

$the_query = new WP_Query( $args );
print_r( $the_query );

```

So if you can use something like that to get the array you want, you can then go from there with a `pre_render`.

```
add_filter("gform_pre_render_22_5", "populate_22_5");
add_filter("gform_admin_pre_render_22_5", "populate_22_5");
 function populate_22_5($form){
  if( $form["id"] != 22 )
  
         return $form;
   
  $items = array();
   
//YOUR QUERY START

$args = array(
    'post_type' => 'advanced_course',
    'areas' => 'pt_subject_courses',
    'order' => 'ASC'
    );              

$the_query = new WP_Query( $args );

// YOUR QUERY END

   if (is_array($the_query ))
{
     foreach($the_query as $abc) $items[] = array( 'value' => $abc, 'text' => $abc );
}
 foreach($form["fields"] as &$field)
    if($field["id"] == 5){
        $field["choices"] = $items;
    }
return $form;
}
```

---

<div class="post-metadata">

**Author:** ![webmgt](https://avatars.discourse-cdn.com/v4/letter/w/77aa72/32.png) [@webmgt](https://community.gravityforms.com/u/webmgt)\
**Post date:** [April 30, 2019, 3:29pm UTC](https://community.gravityforms.com/t/dynamically-populating-drop-down-fields/1683/3 "2019-04-30T15:29:57Z")

</div>

Thank you appreciated. I shall see If I can get anything working out of this.

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 4, 2022, 5:28pm UTC](https://community.gravityforms.com/t/dynamically-populating-drop-down-fields/1683/4 "2022-01-04T17:28:46Z")

</div>


