Hello,
I follow all the steps of this page (http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields). I copied the code in my functions.php file and changed the ID of the form to 6 (the ID of my form).
I've created a test form with a dropdown field (http://www.piratecafe.eu/test/). The field has the checkbox 'Allow field to be populated dynamically' checked, with parameter name 'posts'.
The page where the form should be shown has this shortcode: [gravityform id="6" name="Untitled Form" ajax="true"]
But the result is always the same; the default data of the drop-down gets filled in instead of the post titles I requested. I get the feeling that my website isn't communicating with the function, but it might be something else altogether. I've got no clue of what I'm doing wrong, some help is appreciated. I spent a few hours reading and trying out multiple examples with no positive results...
Thanks in advance!
Once again the entire code from functions.php:
// update the '51' to the ID of your form
add_filter('gform_pre_render_6', 'populate_posts');
function populate_posts($form){
foreach($form['fields'] as &$field){
if($field['type'] != 'select' || strpos($field['cssClass'], 'populate-posts') === false)
continue;
// you can add additional parameters here to alter the posts that are retreieved
// more info: http://codex.wordpress.org/Template_Tags/get_posts
$posts = get_posts('numberposts=-1&post_status=publish');
// update 'Select a Post' to whatever you'd like the instructive option to be
$choices = array(array('text' => 'Select a Post', 'value' => ' '));
foreach($posts as $post){
$choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
}
$field['choices'] = $choices;
}
return $form;
}