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
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.
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