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