Im using this Post as an exmaple:
https://toolset.com/forums/topic/dynamically-populated-third-part-form-field-by-custom-field-of-the-child-post/
It works fine its just that IT loads the Post title of the child post (repeatable group) but I need to get and set the Default value of that Option as well:
Here is the code:
Ill explain data structure after:
add_filter('frm_setup_new_fields_vars', 'frm_populate_posts', 20, 2);
function frm_populate_posts($values, $field) {
// IDs of fields to be modified by this code for this relationship
$modify_fields = array( 29, 7 );
$relationship = "visa-cost-group";
if ( in_array( $field->id, $modify_fields ) ) {
// Get the parent post id from $post or wp_get_referer
// depending on whether initial page load or ajax request
if (wp_doing_ajax()) {
$url = wp_get_referer();
$parent_id = url_to_postid($url);
} else {
global $post;
$parent_id = $post->ID;
}
switch ( $field->id ) {
case '6':
$relationship = "provinces";
break;
case '29':
$relationship = "visa-cost-group";
break;
}
$posts = toolset_get_related_posts(
$parent_id, // get posts related to this one
$relationship, // relationship between the posts
'parent', // get posts where $parent_post is the parent in given relationship
999, 0, // pagination
array(), // arguments not required
'post_object',
'child'
);
unset($values['options']);
$values['options'] = array(''); //remove this line if you are using a checkbox or radio button field
$values['options'][''] = '';
foreach ($posts as $p) {
$values['options'][$p->ID] = array(
'label' => $p->post_title , //change 'Custom label' to your custom label
'value' => $p->types_render_field( "cost"), //change 'Default value' to your default value
);
}
$values['use_key'] = true; //this will set the field to save the post ID instead of post title
unset($values['options'][0]);
}
return $values;
}
What I tried Doing was settingt he options values to an array but that doesnt seem to work.
foreach ($posts as $p) {
$values['options'][$p->ID] = $p->post_title;
}
Works fine to Fill the dropdown with the titles of the Child post. But I need to set the default values on the form to as I need to perform calculations with the Field values ( i do this on the form builder formidable its self) i just need the Title/Values to fill