Skip Navigation

[Resolved] How to automatically change the child author when parent author changes

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

Problem: How to change author of child post based on parent post.

Solution: You can update the child post author by using the CRED hook: "cred_save_data".

You can find proposed solution with the following reply: https://toolset.com/forums/topic/how-to-automatically-change-the-child-author-when-parent-author-changes/#post-409320

Relevant Documentation: => https://toolset.com/documentation/user-guides/cred-api/#csd => https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/

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.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Amin 5 years ago.

Assigned support staff: Minesh.

Author
Posts
#409004

Can you tell me how I can automatically update the author of a child post when the author of it's parent changes?

I have a CRED form where I can change the author of the parent. What i'm looking for is a way to AUTOMATICALLY update the child post's author accordingly.

Can you help?

#409320

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

You can update the child post author by using the CRED hook: "cred_save_data"
https://toolset.com/documentation/user-guides/cred-api/#csd

For example - Add following code to your current theme's functions.php file:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==9999)
    {
         // get your child id based on parent id 
        // once you get child id - write your code to assign author to your child
    }
}

Where :
Replace "9999" with your CRED parent form ID

You can go through the following Docs to know how to fetch child:
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/

I hope above solution will help you to resolve your issue.

#411150

Thank you.