Problem: I have a Form that creates child posts. It works, but I would like to set the post author to be the same as the parent post author.
Solution: In the CRED form for creating child post, there is a a parent post select field. You can access the selected option of the parent post field in the $_POST superglobal. The parameter name will be in the format "@relationship-slug_parent". Then in the cred_save_data hook, you can use the parent post ID to determine the correct post author ID. Try something like this:
$parent_post_id = $_POST['@relationship-slug_parent']; $parent_author_id = get_post_field ('post_author', $parent_post_id); $postarr = array( 'ID' => $post_id, 'post_author' => $parent_author_id ); // MEDARBEJDER insert in database Insert wp_update_post( $postarr );
Replace relationship-slug with the actual slug of your post relationship. So if your post relationship is foo-bar, the parameter name will be @foo-bar_parent.
Relevant Documentation:
https://codex.wordpress.org/Function_Reference/get_post_field
https://codex.wordpress.org/Function_Reference/wp_update_post
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 4 replies, has 2 voices.
Last updated by 5 years, 8 months ago.
Assisted by: Christian Cox.