I have a form that i use to create a CPT post with Advanced Post Creation.
I’ve also set up a relation of one to many between this Custom Post Type and another.
My problem is that i’m not able to work out how to set the post that is being created in the form to be a child post of the post that the form is embedded on. I’m able to do it with Crocoblock’s JetForms but need to use Gravity Forms in order to take advantage of some other features.
I’m able to find the relation in APC but not able to set the new post’s id as the relation, therefore it’s not actually linking the two posts.
Give the following code a try. I think this should work to assign the created post as a child of the page on which the form is embedded. I don’t know how things will be handled internally with WordPress should two posts have different post_type, though.
// Set parent for post created with APC
// @replace {{form_id}}
add_action( 'gform_advancedpostcreation_post_after_creation_{{form_id}}',
function( $post_id, $feed, $entry, $form ) {
wp_update_post( array(
'ID' => $post_id,
'post_parent' => GFCommon::replace_variables( '{embed_post:ID}', $form, $entry )
) );
},
10, 4 );
Unfortunately, i’m not having success. I have been able to map a post meta field to the relation in advanced post creation, and that seems to get the child post (newly created) to show the parent post (for which the form is embedded on) but the parent post does not show the child post and therefore it’s not fully connecting.
The snippet isn’t working either, but it may be due to them being in separate CPTs.