I have a post field group assigned to a post type that then has a parent post type, basically a post type relationship. (https://toolset.com/documentation/user-guides/creating-post-type-relationships/)
I display the custom fields I want in a content template for the output page. A view for the child posts is called within the content template that then displays all the child posts for that post type.
After the page is drawn for the user, I then have a hidden form using Gravity Forms that gets populated with the same data in case a user wants to click an "update" link to then display the form and update any fields on the form that have already been pre-populated.
Hopefully that makes sense. 🙂 If not, here is a page of what I am trying to describe: hidden link
The Vineyard Addresses are the child posts, and then you click update to display the form.
The problem I have is getting the values of those child posts using PHP code in functions.php to then populate the 3 sections of the form that have the Vineyard Addresses info.
I am guessing I need to use some kind of code that is referenced here: https://toolset.com/documentation/customizing-sites-using-php/displaying-child-posts/
But the code currently being used to get the data to send to the form is fine for "upper level" custom fields by creating an array, but the child post ones is what I am struggling with in order to pass the values in the same array.
Here is the code that is being used to get the data right now:
function populate_fields( $value, $field, $name ) {
$mk = filter_gpm( get_post_meta( get_the_ID() ) );
$values = array(
'gf-title' => $mk['wpcf-title'],
'gf-owners' => $mk['wpcf-owners'],
'gf-contact-address' => $mk['wpcf-contact-address'],
....
);
return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}
function array_push_assoc($array, $key, $value){
$array[$key] = $value;
return $array;
}
function filter_gpm($array){
$mk = array();
foreach($array as $k => $v){
if(is_array($v) && count($v) == 1){
$mk = array_push_assoc($mk, $k, $v[0]);
} else {
$mk = array_push_assoc($mk, $k, $v);
}
}
return $mk;
}
I appreciate any help someone can provide on how to fill the form array with the values of the child posts.