I have a toolset form that generates a CPT (equipment), with custom fields consisting of model, year, serial number etc. You also set the post relationship parent (manufacturers-equipments) at the same time. The 'manufacturers' are in a one to many relationship with the equipment. This all works as expected so far.
In addition to this I would like that the CPT parent that is selected in the form, 'manufacturers-equipments' post title to be saved within the 'equipments' CPT custom fields, as 'equipment-manufacturer' for example, so that i can call on that information in a gravity form that requires post meta from the 'equipment' CPT.
Is there any documentation that you are following?
The child posts are published using a Toolset Form which includes a selector for the parent post, and you want the title of the parent post to be saved in some custom field of the child post when the form is submitted, correct?
For that you would need to use the Forms API, a hook such as cred_save_data.
You should be able to identify the ID of the parent post in the $_POST object, and can retrieve the post title using get_post() and save it with update_post_meta(), as required.
Thanks for your input, i managed to also find some help/code from another couple of support threads, and then used this code which works for what I need it to do. One quick question, if i need to to run it for multiple forms, I have just duplicated it in this instance, but could I instead just list the forms with a comma between them?
function ts_update_post_field_with_parent_post_title($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==61)
{
$relationship = 'manufacturer-equipment';//The slug of the relationship you want to target
$manufacturer_id = toolset_get_related_post($post_id, $relationship ); //to get the post id of the related manufacturer
$manufacturer_name = get_the_title( $manufacturer_id ); //to get the post title of the manufacturer specified by the post id
//Example of what to do with such data
update_post_meta($post_id, 'wpcf-equipment-make', $manufacturer_name);
}
// if a specific form
if ($form_data['id']==1292)
{
$relationship = 'manufacturer-equipment';//The slug of the relationship you want to target
$manufacturer_id = toolset_get_related_post($post_id, $relationship ); //to get the post id of the related manufacturer
$manufacturer_name = get_the_title( $manufacturer_id ); //to get the post title of the manufacturer specified by the post id
//Example of what to do with such data
update_post_meta($post_id, 'wpcf-equipment-make', $manufacturer_name);