Creation of Child Post

Hey there!

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.

Any help will be greatly appreciated!

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 );
2 Likes

hey Joshua, thanks for the help!

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.

Here’s an example of having used APC to map the relation. It shows on the child post but not the parent post.

I can show screenshots of the child post showing the correct author but the parent post not showing the correct child post.

Screen Shot 2021-10-01 at 9.46.24 AM

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.