# Creation of Child Post

**URL:** <https://community.gravityforms.com/t/creation-of-child-post/10825>\
**Category:** Get Help\
**Tags:** apc, gform\_advancedpostcreation\_post\_after\_creation, cpt, parent\
**Created:** [September 29, 2021, 7:13pm UTC](https://community.gravityforms.com/t/creation-of-child-post/10825 "2021-09-29T19:13:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5ba0f87b08b984.7](https://avatars.discourse-cdn.com/v4/letter/u/e480ec/32.png) [@user5ba0f87b08b984.7](https://community.gravityforms.com/u/user5ba0f87b08b984.7)\
**Post date:** [September 29, 2021, 7:13pm UTC](https://community.gravityforms.com/t/creation-of-child-post/10825/1 "2021-09-29T19:13:42Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![uamv](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/uamv/32/1412_2.png) [@uamv](https://community.gravityforms.com/u/uamv)\
**Post date:** [September 30, 2021, 8:29pm UTC](https://community.gravityforms.com/t/creation-of-child-post/10825/2 "2021-09-30T20:29:19Z")

</div>

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.

```auto
// 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 );

```

---

<div class="post-metadata">

**Author:** ![user5ba0f87b08b984.7](https://avatars.discourse-cdn.com/v4/letter/u/e480ec/32.png) [@user5ba0f87b08b984.7](https://community.gravityforms.com/u/user5ba0f87b08b984.7)\
**Post date:** [October 1, 2021, 1:16pm UTC](https://community.gravityforms.com/t/creation-of-child-post/10825/3 "2021-10-01T13:16:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![user5ba0f87b08b984.7](https://avatars.discourse-cdn.com/v4/letter/u/e480ec/32.png) [@user5ba0f87b08b984.7](https://community.gravityforms.com/u/user5ba0f87b08b984.7)\
**Post date:** [October 1, 2021, 1:49pm UTC](https://community.gravityforms.com/t/creation-of-child-post/10825/4 "2021-10-01T13:49:16Z")

</div>

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

 ![Screen Shot 2021-10-01 at 9.46.59 AM](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/9/99648a359de7bf12d55937d0e5f9b12b333dc6a2.png)

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

---

<div class="post-metadata">

**Author:** ![user5ba0f87b08b984.7](https://avatars.discourse-cdn.com/v4/letter/u/e480ec/32.png) [@user5ba0f87b08b984.7](https://community.gravityforms.com/u/user5ba0f87b08b984.7)\
**Post date:** [October 1, 2021, 1:49pm UTC](https://community.gravityforms.com/t/creation-of-child-post/10825/5 "2021-10-01T13:49:52Z")

</div>

![Screen Shot 2021-10-01 at 9.46.24 AM](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/7/7b5d37fe2ea0e87b597ebdcffcec11dda16f68b5.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [October 31, 2021, 1:50pm UTC](https://community.gravityforms.com/t/creation-of-child-post/10825/6 "2021-10-31T13:50:24Z")

</div>

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