Skip Navigation

[Resolved] Cannot get parent/child post meta from cred_save_data

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2666785

Tell us what you are trying to do?
- I have a CRED form that connects existing parent post with a child post and it looks like this:

[credform]
	<div class="form-group">
		<label for="%%FORM_ID%%_@radiologist-to-report-request.parent">[cred_i18n name='@radiologist-to-report-request.parent-label']Radiologists[/cred_i18n]</label>
		[cred_field field='@radiologist-to-report-request.parent' class='form-control radiologist-to-report-request-field' output='bootstrap' select_text='--- not set ---' required='false']
	</div>
	[cred_field field='form_messages' class='alert alert-warning']
	[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]

- I am using cred_save_data to get information from a parent post field='@radiologist-to-report-request.parent' in order to use it further to update a child post field.
The code looks like this:

add_action('cred_save_data', 'rad_order_toolset_associations_created',10,2);
function rad_order_toolset_associations_created( $post_id, $form_data )
{	
    if ( $form_data['id']==number )
    {	
    
    $rad_post_id = $_POST['@radiologist-to-report-request.parent'];
      	error_log( "rad_post_info: " .  $rad_post_id );

        $rad_first_name = get_post_meta($rad_post_id, 'wpcf-radiologist-first-name', true);
        $rad_last_name = get_post_meta($rad_post_id, 'wpcf-radiologist-last-name', true);    
      	update_post_meta($post_id, 'wpcf-associated-radiologist-to-report-order-name', $rad_first_name . " " . $rad_last_name);
    }
}

For some reason, I get nothing from the parent field ( $rad_post_id = $_POST['@radiologist-to-report-request.parent'];) Error log shows nothing from this field.
There is no PHP errors in logs and the form itself works ok (means that the parent post is getting connected to the child post).
Therefore I would like to ask you to point out what I am missing here.

Is there any documentation that you are following?
- Yes:
- - https://toolset.com/forums/topic/cannot-get-parent-child-post-meta-from-cred_save_data/
- -https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete

Is there a similar example that we can see?
- I can't find any ready working solution, sorry.

What is the link to your site?
- hidden link

#2666787

Hi,

Thank you for contacting us and I'd be happy to assist.

In your custom function, can you try printing the entire '$_POST' variable, to see the complete data it is bringing in?

Example:


error_log(print_r($_POST, true));

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2666793

Hi Waqar, thank you for your advice.
After printing the $_POST variable I found that I wasn't referencing the parent post field correctly.
I should have use $_POST[@radiologist-to-report-request_parent'] instead of $_POST['@radiologist-to-report-request.parent']. It's something I didn't know, honestly.

cassianS confirmed that the issue was resolved on 2023-11-21 07:16:23.
This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.