<?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: Can Radio Buttons be dynamically populated by a custom field array</title>
		<link>https://legacy.forums.gravityhelp.com/topic/can-radio-buttons-be-dynamically-populated-by-a-custom-field-array</link>
		<description>Gravity Support Forums Topic: Can Radio Buttons be dynamically populated by a custom field array</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 22:06:27 +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/can-radio-buttons-be-dynamically-populated-by-a-custom-field-array" rel="self" type="application/rss+xml" />

		<item>
			<title>Chris Hajer on "Can Radio Buttons be dynamically populated by a custom field array"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/can-radio-buttons-be-dynamically-populated-by-a-custom-field-array#post-92200</link>
			<pubDate>Sat, 17 Nov 2012 01:54:32 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">92200@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I'm certain your code will help someone.  Looks like a very nice solution. Thank you for sharing it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>thirtypointfour on "Can Radio Buttons be dynamically populated by a custom field array"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/can-radio-buttons-be-dynamically-populated-by-a-custom-field-array#post-91200</link>
			<pubDate>Wed, 14 Nov 2012 21:06:40 +0000</pubDate>
			<dc:creator>thirtypointfour</dc:creator>
			<guid isPermaLink="false">91200@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;All Fixed!&#60;/p&#62;
&#60;p&#62;Simply replace lines 19,20 &#38;amp; 21 with the following:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;if (is_array($metas))
{
foreach($metas as $meta)  $items[] = array(&#38;quot;value&#38;quot; =&#38;gt; $meta, &#38;quot;text&#38;quot; =&#38;gt; $meta);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;So the whole function should then look like this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;populate_radio_buttons&#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_radio_buttons&#38;quot;);

function populate_radio_buttons($form){

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

    return $form;

    //Creating radio button item array.
    $items = array();
    // Get the custom field values stored in the array
    $metas = get_post_meta( get_the_ID(), &#38;#39;tour_dates&#38;#39;, true );

if (is_array($metas))
{
foreach($metas as $meta)  $items[] = array(&#38;quot;value&#38;quot; =&#38;gt; $meta, &#38;quot;text&#38;quot; =&#38;gt; $meta);
}
    //Adding items to field id 10. Replace 10 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;] == 10){
            $field[&#38;quot;choices&#38;quot;] = $items;
        }

    return $form;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Hope this helps others with the same needs.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>thirtypointfour on "Can Radio Buttons be dynamically populated by a custom field array"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/can-radio-buttons-be-dynamically-populated-by-a-custom-field-array#post-91178</link>
			<pubDate>Wed, 14 Nov 2012 18:31:15 +0000</pubDate>
			<dc:creator>thirtypointfour</dc:creator>
			<guid isPermaLink="false">91178@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I have managed to almost do this bar one error when visiting the form in the backend!! &#60;/p&#62;
&#60;p&#62;&#60;strong&#62;Warning: Invalid argument supplied for foreach()  on line 19&#60;/strong&#62;&#60;/p&#62;
&#60;p&#62;this refers to the line:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;foreach ( $metas as $meta )&#38;#39;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Below is what I am using which currently works front end but unfortunately is throwing up an error when I go to the form in the backend of wordpress:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;populate_radio_buttons&#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_radio_buttons&#38;quot;);

function populate_radio_buttons($form){

    //only populating radio buttons in form id 5
    if($form[&#38;quot;id&#38;quot;] != 5)

    return $form;

    //Creating radio buttons item array.
    $items = array();

    //To add an initial value uncomment this next line
    //$items[] = array(&#38;quot;text&#38;quot; =&#38;gt; &#38;quot;Please Select&#38;quot;, &#38;quot;value&#38;quot; =&#38;gt; &#38;quot;&#38;quot;);
    // Get the custom field values stored in the array
    $metas = get_post_meta( get_the_ID(), &#38;#39;tour_dates&#38;#39;, true );
    foreach ( $metas as $meta )
    // Add the Values to the drop down
    $items[] = array(&#38;quot;value&#38;quot; =&#38;gt; $meta, &#38;quot;text&#38;quot; =&#38;gt; $meta);

    //Adding items to field id 7. Replace 7 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;] == 7){
            $field[&#38;quot;choices&#38;quot;] = $items;
        }

    return $form;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Any thoughts on this?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>thirtypointfour on "Can Radio Buttons be dynamically populated by a custom field array"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/can-radio-buttons-be-dynamically-populated-by-a-custom-field-array#post-91055</link>
			<pubDate>Wed, 14 Nov 2012 07:20:56 +0000</pubDate>
			<dc:creator>thirtypointfour</dc:creator>
			<guid isPermaLink="false">91055@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I am building a tour company website and I'm using a custom post type called &#34;Tours&#34; which has a number of custom fields associated with it.&#60;/p&#62;
&#60;p&#62;One of the custom fileds is used to store multiple &#34;Departure Dates&#34; associated with the tour.  I'm using the Deluxe Blog Tips Meta Box script which allows you to clone a custom fields (in the backend) thus creating an array of values associated with the one custom field.  For example I am currently outputting these values as follows in the template:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;$metas = get_post_meta( get_the_ID(), &#38;#39;tour_dates&#38;#39;, true );
foreach ( $metas as $meta )
{ echo $meta; }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This Outputs a simple list of dates (or what ever is added in the custom field) such as:&#60;/p&#62;
&#60;p&#62;29th September 2012&#60;br /&#62;
15th October 2012&#60;br /&#62;
23rd November 2012&#60;/p&#62;
&#60;p&#62;What I am wanting to do is put a simple pre-booking form at the bottom of the tour page.  On this form I want users to be able to select a tour date they want to book.  &#60;/p&#62;
&#60;p&#62;Finally the question:&#60;/p&#62;
&#60;p&#62;&#60;strong&#62;Is it possible to dynamically populate a Radio Button list with the various departure dates (any value) coming from an array of values stored in a single custom field?&#60;/strong&#62;&#60;/p&#62;
&#60;p&#62;Ideally the form will have a hidden field populated by the post title (that bits easy) and the pre populated radio button list (thats where I am stuck!!) for the user to select the dates that suit them.&#60;/p&#62;
&#60;p&#62;If this is possible I'll simply pass the Page Title &#38;amp; The Selected Departure Date to a generic booking form, (on another page) where the client can fill out all their contact details ect, and keep the main tour page simple.&#60;/p&#62;
&#60;p&#62;Would be great to hear if this is possible and if anyone has done anything similar.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
