<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Populating Drop Down with value from ACF field</title>
		<link>https://legacy.forums.gravityhelp.com/topic/populating-drop-down-with-value-from-acf-field</link>
		<description>Gravity Support Forums Topic: Populating Drop Down with value from ACF field</description>
		<language>en-US</language>
		<pubDate>Sun, 05 Apr 2026 16:24:26 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/populating-drop-down-with-value-from-acf-field" rel="self" type="application/rss+xml" />

		<item>
			<title>David Peralty on "Populating Drop Down with value from ACF field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/populating-drop-down-with-value-from-acf-field#post-61024</link>
			<pubDate>Thu, 31 May 2012 14:17:46 +0000</pubDate>
			<dc:creator>David Peralty</dc:creator>
			<guid isPermaLink="false">61024@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Glad you were able to figure it out. Thanks for posting your solution.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bghouse on "Populating Drop Down with value from ACF field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/populating-drop-down-with-value-from-acf-field#post-60984</link>
			<pubDate>Thu, 31 May 2012 11:52:30 +0000</pubDate>
			<dc:creator>bghouse</dc:creator>
			<guid isPermaLink="false">60984@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Okay, I solved it!  There is probably a much cleaner way of doing this, but it's working for me.&#60;br /&#62;
I created a new array and used IF statements to check the ACF field array to see what values are set for that post, and used array_push to build this new array with only the values that should be there.&#60;/p&#62;
&#60;p&#62;Then, I use this new array as the base for the foreach statement that builds the choices items.&#60;/p&#62;
&#60;p&#62;Here's my code in case anyone else is trying to do something similar with Gravity Forms and ACF.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;populate_dropdown&#38;quot;);

//Note: when changing drop down values, we also need to use the gform_admin_pre_render so that the right values are displayed when editing the entry.
add_filter(&#38;quot;gform_admin_pre_render&#38;quot;, &#38;quot;populate_dropdown&#38;quot;);

function populate_dropdown($form){

    //only populating drop down for form id 1 - change to be your form id
    if($form[&#38;quot;id&#38;quot;] != 1)
       return $form;

    //Create a new array from the values in the acf field.
    //Using if command to only grab the values that exist for that post, repeat as needed
    $chartertypes = array();

    if(in_array(&#38;#39;offshore&#38;#39;, get_field(&#38;#39;charter_types&#38;#39;) ))
	array_push($chartertypes, &#38;quot;Deep Sea Offshore&#38;quot;);

    if(in_array(&#38;#39;flat&#38;#39;, get_field(&#38;#39;charter_types&#38;#39;) ))
	array_push($chartertypes, &#38;quot;Backcountry Flats&#38;quot;);

    //Creating drop down item array.
    $items = array();

    //Adding initial blank value.
    $items[] = array(&#38;quot;text&#38;quot; =&#38;gt; &#38;quot;Select Charter Type&#38;quot;, &#38;quot;value&#38;quot; =&#38;gt; &#38;quot;&#38;quot;);

    //Adding charter type values to the items array
    foreach($chartertypes as $chartertype)
       $items[] = array(&#38;quot;value&#38;quot; =&#38;gt; $chartertype, &#38;quot;text&#38;quot; =&#38;gt; $chartertype);

    //Adding items to field id 4. Replace 4 with your actual field id. You can get the field id by looking at the input name in the markup.
    foreach($form[&#38;quot;fields&#38;quot;] as &#38;amp;$field)
        if($field[&#38;quot;id&#38;quot;] == 4){
            $field[&#38;quot;choices&#38;quot;] = $items;
        }

    return $form;
    }&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>bghouse on "Populating Drop Down with value from ACF field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/populating-drop-down-with-value-from-acf-field#post-60966</link>
			<pubDate>Thu, 31 May 2012 10:15:49 +0000</pubDate>
			<dc:creator>bghouse</dc:creator>
			<guid isPermaLink="false">60966@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks David, although not what I wanted to hear 'cause it doesn't work :-(&#60;/p&#62;
&#60;p&#62;Okay, I'm off to talk to Elliot and see if we can figure this out.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Peralty on "Populating Drop Down with value from ACF field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/populating-drop-down-with-value-from-acf-field#post-60858</link>
			<pubDate>Wed, 30 May 2012 15:41:34 +0000</pubDate>
			<dc:creator>David Peralty</dc:creator>
			<guid isPermaLink="false">60858@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;You might want to talk to the plugin maker of ACF because your code, in terms of putting data into a drop down is correct from the Gravity Forms side if the values are stored in a normal array.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bghouse on "Populating Drop Down with value from ACF field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/populating-drop-down-with-value-from-acf-field#post-60852</link>
			<pubDate>Wed, 30 May 2012 15:24:21 +0000</pubDate>
			<dc:creator>bghouse</dc:creator>
			<guid isPermaLink="false">60852@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I'm trying to figure out the code for the gform_pre_render that will allow me to pull the data stored in my ACF custom field and populate a drop down list.&#60;/p&#62;
&#60;p&#62;I'm not trying to create posts or update the database, just an email contact form.  I have a multi-selection field in ACF called &#34;charter_types&#34; that works with a custom post type.  I need to add a contact form on the post type, and have the Charter Type dropdown field populated with the multiple values entered on each post.&#60;/p&#62;
&#60;p&#62;I've tried various code, but just can't quite get this figured out.  Example if this will help.&#60;/p&#62;
&#60;p&#62;Post 1:  field &#34;charter_type&#34; has 2 values stored, &#34;offshore&#34; and &#34;fly&#34;.&#60;br /&#62;
Post 2: field &#34;charter_type&#34; has 3 values store, &#34;offshore&#34;, &#34;fly&#34; and &#34;tarpon&#34;.&#60;/p&#62;
&#60;p&#62;When displaying gform 1 on Post 1, the Drop-Down field labeled Select Charter Type needs to display only &#34;offshore&#34; and &#34;fly&#34;.&#60;/p&#62;
&#60;p&#62;When displaying gform 1 on Post 2, the Drop-Down field needs to display &#34;offshore&#34;, &#34;fly&#34; and &#34;tarpon&#34;.&#60;/p&#62;
&#60;p&#62;This code seems to be the closest, but I'm getting an invalid argument supplied on the for each.  &#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;populate_dropdown&#38;quot;);

//Note: when changing drop down values, we also need to use the gform_admin_pre_render so that the right values are displayed when editing the entry.
add_filter(&#38;quot;gform_admin_pre_render&#38;quot;, &#38;quot;populate_dropdown&#38;quot;);

function populate_dropdown($form){

    //only populating drop down for form id 1
    if($form[&#38;quot;id&#38;quot;] != 1)
       return $form;

    //Reading values from custom field charter_types
    $chartertypes = get_field(&#38;#39;charter_type&#38;#39;);

    //Creating drop down item array.
    $items = array();

    //Adding initial blank value.
    $items[] = array(&#38;quot;text&#38;quot; =&#38;gt; &#38;quot;&#38;quot;, &#38;quot;value&#38;quot; =&#38;gt; &#38;quot;&#38;quot;);

    //Adding charter type values to the items array
    foreach($chartertypes as $chartertype)
        $items[] = array(&#38;quot;value&#38;quot; =&#38;gt; $chartertype, &#38;quot;text&#38;quot; =&#38;gt; $chartype);

    //Adding items to field id 4. Replace 4 with your actual field id. You can get the field id by looking at the input name in the markup.
    foreach($form[&#38;quot;fields&#38;quot;] as &#38;amp;$field)
        if($field[&#38;quot;id&#38;quot;] == 4){
            $field[&#38;quot;choices&#38;quot;] = $items;
        }

    return $form;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I think this might be related to another post talking about how ACF stores these values serialized in the DB.&#60;/p&#62;
&#60;p&#62;Is there any solution I can use here?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
