Skip Navigation

[Gelöst] get parent post data and create child post title using CRED form

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.


Use a CRED form for creating child post, I need to get parent post information within cred_save_data action hook using PHP codes.


In the CRED form for creating child post, there is a a parent post selector, it will pass a POST parameter "@client-client-portfolio_parent" to target page, so you will can get the parent post ID with below codes:

$parent_post_id = $_POST['@client-client-portfolio_parent'];

Relevant Documentation:

This support ticket is created vor 5 Jahre. There's a good chance that you are reading advice that it now obsolete.

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/Hong_Kong (GMT+08:00)

This topic contains 2 Antworten, has 2 Stimmen.

Last updated by davidZ-4 vor 5 Jahre.

Assisted by: Luo Yang.


Tell us what you are trying to do? create a child post using a from and give it a dynamic name with data from the parent post

Is there any documentation that you are following?

Is there a similar example that we can see?
not sure

What is the link to your site?
hidden link

I have tried multiple solutions but couldn't get this to work.
i can create a dynamic name for a post but cannot get the parent data to insert to the child post.
both parent and child posts are with status Private

here is one of the codes i tried

//Create a dynamic post title by the CRED form.
add_action('cred_save_data', 'func_custom_post_title', 10, 2);
function func_custom_post_title($post_id, $form_data)
	$author = get_the_author();
	$user_id =  get_the_author_meta('ID');
	//if new client - parent post dynamic name works just fine
	if ($form_data['id'] == 283 ) {
		$author = get_the_author();
		$user_id =  get_the_author_meta('ID');
		$post_type = get_post_type( $post_id ); 
		$cfn = get_post_meta($post_id, 'wpcf-client-first-name', true);
		$cln = get_post_meta($post_id, 'wpcf-client-last-name', true);
		$cshrtid = get_post_meta($post_id, 'wpcf-client-id-number', true);
		$title = $cfn.' '.$cln.' '.$user_id.'-'.$cshrtid.'-'.$post_id;
		$slug = sanitize_title($title);
		$args = array('ID' => $post_id, 'post_title' => $title, 'post_name'=>$slug);
	//if new portfolio -child post cannot get the parent post data so this is not working
	if ($form_data['id'] == 386 ) {
//get data from parent post i tried this option
		$parent_post_id = toolset_get_related_post( $post_id, 'client-client-portfolio', 'client' );		
// and i tried this option
		$child_post_id = get_post($post_id);
		$parent_post_id = toolset_get_related_post( $child_post_id, 'client-client-portfolio', 'parent');
		$cfn = get_post_meta($parent_post_id, 'wpcf-client-first-name', true);
		$cln = get_post_meta($parent_post_id, 'wpcf-client-last-name', true);
		$cshrtid = get_post_meta($parent_post_id, 'wpcf-client-id-number', true);
		//get data from current post		
		//$post_type = get_post_type( $post_id );
		// Get the title of the parent (client) post
		$title = $cfn.' '.$cln.' '.$user_id.'-'.$cshrtid.'-'.$parent_post_id.'-P'.$post_id;
		$slug = sanitize_title($title);
		$args = array('ID' => $post_id, 'post_title' => $title, 'post_name'=>$slug);

please advise,


Dear David,

I assume we are talking about same website as your previous thread:

I have checked the database dump file again, in the form ID 386, there is a hidden parent post selector, after user submit the form, it will pass a POST parameter "@client-client-portfolio_parent" to target page, so you will can get the parent post ID with below codes:

$parent_post_id = $_POST['@client-client-portfolio_parent'];

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.