Hi
We need development help with Gravity Forms and Custom Post Types front end forms - we're looking to populate a number of dropdowns in front end forms dynamically with various values drawn from a range of custom post types on a WordPress site we're building.
Thanks
Marcus
Kyle answers:
This should work:
add_filter('gform_pre_render_x', 'populate_postS');
function populate_postS($form){
foreach($form["fields"] as &$field){
if($field["id"] == x2){
$args = array( );
$QS = new WP_Query( $args);
$field['choices'] = array();
foreach ($QS as $Q){
$name = $Q->post_title;
$val = $Q->ID;
$field['choices'][] = array( 'text' => $name, 'value' => $val);
}
}
}
return $form;
}
Replace x with your form id and x2 with the field id
Kyle comments:
Then you just have to add whatever arguments you need to pull certain posts to the $args array
marcusjwilson comments:
Thanks Kyle - yes, we'd used something similar but it wasn't populating properly. Arnav worked it out for us.
Firoja_Imtosupport answers:
Hi Marcus,
Please can you provide a screenshot of which fields you want on frontend?