Skip Navigation

[Resolved] Changing child post author on save to the author of the parent custom post type

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 replies, has 2 voices.

Last updated by nicholasE 1 year, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2560469

Hi

We have used to Toolset to create two custom post types and connect them in a parent-child relationship. The parent post type is called "Room" and the child post type is called "Event". There is a one to many relationship from "Room" to "Event". i.e. a single room can have many events.

A "Room" is "owned" and managed by the author of that Room. Events for that room can be created by anyone. We use a front end toolset form to allow users to create events. That form uses a query string parameter to pre-select the parent Room. This all works very well so we have events linked back to rooms.

The problem is that regardless of who the user is who created an event via the front end form, we need to immediately change the author of the event to be the author of the parent Room. This is to allow the Room author to review and manage events.

Is there a way we can change the author of the event to be the author of the room when the event is saved from the front end form. To do this we would need to find the author of the parent Room.

If this is possible, an example would be very much appreciated.

Thank you
Nick

#2560617

Hello,

It is possible with custom codes, for example:
1) After user submit the child post form for creating new "event" post, you can use action hook "cred_save_data" to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

2) In this PHP function:
a) Get the related "Room" post ID:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
b) Get the "Room" post author ID:
https://developer.wordpress.org/reference/functions/get_post_field/
c) Update "event" post author ID:
https://developer.wordpress.org/reference/functions/wp_update_post/

For your reference.

#2562235

Thank you for the information. It will be a few days before I can look at this further so I will close this ticket. If I have more specific questions once I review the information you supplied, I will raise a new ticket.

Thanks
Nick