Skip Navigation

[Resolved] Save post title with parent post name

This thread is resolved. Here is a description of the problem and solution.

Problem:
Save post title with parent post ID using Toolset form

Solution:
You can use Toolset Form hook "cred_save_data" to update the post title on fly.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/save-post-title-with-parent-post-name/#post-1176005

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 5 years, 10 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by domenicoS 5 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1175916

Hi,

Hi trying to automatically set the post name when created with a cred form.

I tried this, but something does not works because it does not take me the Parent ID. What is wrong?

add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data ) {
    if ($form_data['id']==4352) {
		$parent_id = toolset_get_related_post( $post_id, 'destination-who-s-who',  'parent');
        $title= $parent_id. '-' . $post_id ;
		wp_update_post(array('ID' => $post_id, 'post_title' => $title));
    }
}

After saving the form I aspect to see a new post with the title: PARENTID-POSTID

relationship slug: destination-who-s-who

#1175934

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - the code you shared looks just fine but why its not showing the desired title with the parent ID, I need to investigate that on your install.

Could you please share problem URL where you added the form?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1175953

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I checked the access details you shared but unfortunately the access details you shared when I try to load the wp-admin link - it says "This site can’t be reached". I could not able to access the site.

Could you please make sure the site should work at this end so I can login to it.

#1175988

Sorry, there was a http problem. I set the website in https, so you can now be able to access I hope.
Pleae update the like I shared with you adding https://

#1176005

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now, I've adjust the code as given under:

add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data ) {
    if ($form_data['id']==4352) {
				
		$parent_id = $_POST['@destination-who-s-who_parent'];
        $title= $parent_id. '-' . $post_id;
		wp_update_post(array('ID' => $post_id, 'post_title' => $title,'post_name' => $title));
    }
}

I can see its displaying current parent ID and child ID information.

#1176012

My issue is resolved now. Thank you Minesh!

#1176021

Hi Minesh,

I checked the page. The title is correct, but not the link because it contains the classic "cred slug" (cred-auto-draft-3c9bece90c3091f58a531b75bfb77508-5) and not the title slug

#1176047

My issue is resolved now. Thank you!

I use this code

wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'post_name' => $title));