Skip Navigation

[Resolved] Dynamic title of child post based on parent posts names

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

Problem: I would like to use the cred_save_data hook to modify the title of the post using information from its parent posts. I can get the parent post IDs using _wpcf_belongs_slug_id, but I do not know how to get the title of those posts using the IDs.

Solution: Use the WordPress get_the_title() function to retrieve a post's title using the post's ID.

get_the_title($post_id);

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

This support ticket is created 7 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by romanB-3 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#554415

Hello,
I have this function

//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) {
    if ($form_data['id']==26) {
        $produit = get_post_meta($post_id, '_wpcf_belongs_produit_id', true);
        $fournisseur = get_post_meta($post_id, '_wpcf_belongs_fournisseur_id', true);
        $title= 'Offre de ' .$produit. ' par ' . $fournisseur;
        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
    }
}

which gives a title based on the parent posts ids. I need to replace those ids by the post names. How could I do this ?
Thank you.

#554483

WordPress has a get_the_title method that accepts the ID and returns the title:
https://developer.wordpress.org/reference/functions/get_the_title/

get_the_title($produit);
#554489

Thank you ; that made it.