Skip Navigation

[Resolved] Add name of the parent in the title of the child in relationship

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

Problem:

Get the parent post title within action hook cred_save_data.

Solution:

It is a custom PHP codes issue, for example:

https://toolset.com/forums/topic/add-name-of-the-parent-in-the-title-of-the-child-in-relationship/#post-1775289

Relevant Documentation:

https://developer.wordpress.org/reference/functions/get_the_title/

This support ticket is created 3 years, 6 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
- 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 replies, has 2 voices.

Last updated by Guillaume 3 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1775283

Hello,

I have 2 CPT with a relationship 1 to many.
For example my "parent" is called Amazon, I wish to automatically add this name to the name of the "child" for example "Amazon - Homepage" where Amazon is the title of the parent in the relationship and Homepage is a custom field from the child.

I fund this topic and it works great : https://toolset.com/forums/topic/add-auto-generate-post-title-from-fields/

But in the example they use 2 custom fields.
I ask if it is possible to use the name of the parent instead ?

Thanks

#1775289

Hello,

It is possible, you can replace those codes from:

    $start_datum = get_post_meta( $post_id, 'wpcf-kurs-start', true );
    $kurs_titel = get_post_meta( $post_id, 'wpcf-kurs-titel', true );
         
    $new_title = $start_datum . " " . $kurs_titel;

With:

$parent_id = $_POST['@' . 'RELATIONSHIP_SLUG' . '_parent'];
$parent_title = get_the_title($parent_id );
$my_field = get_post_meta( $post_id, 'wpcf-' . 'my-field', true );
$new_title = $parent_title . "-" . $my_field;

Please replace "RELATIONSHIP_SLUG" with your custom post type relationship slug
replace "my-field" with your custom field slug, and test again.

More help:
https://developer.wordpress.org/reference/functions/get_the_title/

#1775309

My issue is resolved now. Thank you very much.

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