<?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: Dynamically populating a drop-down custom field</title>
		<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-a-drop-down-custom-field</link>
		<description>Gravity Support Forums Topic: Dynamically populating a drop-down custom field</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 22:19:43 +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/dynamically-populating-a-drop-down-custom-field" rel="self" type="application/rss+xml" />

		<item>
			<title>Chris Hajer on "Dynamically populating a drop-down custom field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-a-drop-down-custom-field#post-69442</link>
			<pubDate>Fri, 03 Aug 2012 21:53:15 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">69442@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;@seahoss, thanks for the update.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>seahoss on "Dynamically populating a drop-down custom field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-a-drop-down-custom-field#post-69326</link>
			<pubDate>Fri, 03 Aug 2012 13:10:12 +0000</pubDate>
			<dc:creator>seahoss</dc:creator>
			<guid isPermaLink="false">69326@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;That worked! Great. Thank you.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "Dynamically populating a drop-down custom field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-a-drop-down-custom-field#post-69295</link>
			<pubDate>Fri, 03 Aug 2012 10:42:31 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">69295@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;The issue is that custom fields are a little different than a regular drop down field, and the code needs to be slightly adjusted.&#60;br /&#62;
Try the following:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;#39;gform_pre_render_1&#38;#39;, &#38;#39;populate_posts&#38;#39;);
function populate_posts($form){
    foreach($form[&#38;#39;fields&#38;#39;] as &#38;amp;$field){
        if($field[&#38;#39;inputType&#38;#39;] != &#38;#39;select&#38;#39; &#124;&#124; strpos($field[&#38;#39;cssClass&#38;#39;], &#38;#39;populate-posts&#38;#39;) === false)
            continue;
        $posts = get_posts(&#38;#39;numberposts=-1&#38;amp;post_status=publish&#38;amp;category_name=members&#38;#39;);
        $choices = array(array(&#38;#39;text&#38;#39; =&#38;gt; &#38;#39;Select a member company&#38;#39;, &#38;#39;value&#38;#39; =&#38;gt; &#38;#39; &#38;#39;));
        foreach($posts as $post){
            $choices[] = array(&#38;#39;text&#38;#39; =&#38;gt; $post-&#38;gt;post_title, &#38;#39;value&#38;#39; =&#38;gt; $post-&#38;gt;post_title);
        }
        $field[&#38;#39;choices&#38;#39;] = $choices;
    }
    return $form;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>seahoss on "Dynamically populating a drop-down custom field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-a-drop-down-custom-field#post-69218</link>
			<pubDate>Thu, 02 Aug 2012 16:00:28 +0000</pubDate>
			<dc:creator>seahoss</dc:creator>
			<guid isPermaLink="false">69218@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi, I'm having the same problem. I can get a typical drop-down field to populate with a custom post type, but not the custom-field drop down - it just won't populate. Please help, as this is how Wordpress can really be used like a relational database, by populating custom fields with ID's of custom post types.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Dynamically populating a drop-down custom field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-a-drop-down-custom-field#post-69040</link>
			<pubDate>Wed, 01 Aug 2012 16:50:06 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">69040@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Do you have a link to this online?  And is that the actual code you are using to populate the drop down currently, the non-working code?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Shawn on "Dynamically populating a drop-down custom field"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-populating-a-drop-down-custom-field#post-68997</link>
			<pubDate>Wed, 01 Aug 2012 14:12:13 +0000</pubDate>
			<dc:creator>Shawn</dc:creator>
			<guid isPermaLink="false">68997@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I've snagged some code from this forum that helps me dynamically populate a category of posts into a drop down menu.&#60;/p&#62;
&#60;p&#62;However, If i try to use a custom field drop down menu instead of a regular drop down menu (using same specifications), the drop down will not dynamically populate.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;/* Dynamic drop-down on /register
------------------------------------------------------ */
add_filter(&#38;#39;gform_pre_render_1&#38;#39;, &#38;#39;populate_posts&#38;#39;);
function populate_posts($form){
    foreach($form[&#38;#39;fields&#38;#39;] as &#38;amp;$field){
        if($field[&#38;#39;type&#38;#39;] != &#38;#39;select&#38;#39; &#124;&#124; strpos($field[&#38;#39;cssClass&#38;#39;], &#38;#39;populate-posts&#38;#39;) === false)
            continue;
        $posts = get_posts(&#38;#39;numberposts=-1&#38;amp;post_status=publish&#38;amp;category_name=members&#38;#39;);
        $choices = array(array(&#38;#39;text&#38;#39; =&#38;gt; &#38;#39;Select a member company&#38;#39;, &#38;#39;value&#38;#39; =&#38;gt; &#38;#39; &#38;#39;));
        foreach($posts as $post){
            $choices[] = array(&#38;#39;text&#38;#39; =&#38;gt; $post-&#38;gt;post_title, &#38;#39;value&#38;#39; =&#38;gt; $post-&#38;gt;post_title);
        }
        $field[&#38;#39;choices&#38;#39;] = $choices;
    }
    return $form;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Any ideas on what I can do differently with this script to ensure I can dynamically populate a custom field (drop down) ?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
