{"id":1727299,"date":"2020-09-15T12:47:45","date_gmt":"2020-09-15T12:47:45","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=1727299"},"modified":"2020-09-15T12:47:45","modified_gmt":"2020-09-15T12:47:45","slug":"selecting-parent-posts-when-using-forms-to-create-child-items","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/de\/course-lesson\/selecting-parent-posts-when-using-forms-to-create-child-items\/","title":{"rendered":"Selecting Parent Posts when Using Forms to Create Child Items"},"content":{"rendered":"\n<p>For example, you could have custom post types for \u201cEvents\u201d and \u201cVenues.\u201d An event can have only one venue, whereas a venue can be used for many events. Your front-end form for creating events can feature a field for selecting a venue for the event being created.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"b2e9b8408f720f1c1f8c99d5b5a91eac\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-form-for-child-posts-with-parent-selector.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-form-for-child-posts-with-parent-selector-500x210.png\" alt=\"\" class=\"wp-image-1732105\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Form for creating child posts with a selector for the parent post<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div class=\"tb-fields-and-text\" data-toolset-blocks-fields-and-text=\"360284519b991feb492b582c7d84725f\"><p>Here we describe cases in which the post-relationship is either one-to-many or one-to-one. Visit the related documentation if you need to create <a href=\"https:\/\/toolset.com\/de\/course-lesson\/front-end-relationship-forms-for-connecting-posts\/\">forms for connecting posts in a many-to-many relationship<\/a>.<\/p><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-forms-with-selectors-for-the-parent-post\">Creating Forms that Allow to Select a Parent Post<\/h2>\n\n\n\n<p>First, let&#8217;s see a case where you create a form for submitting child posts (i.e. events) but you want to allow users to select a parent post of their choosing.<\/p>\n\n\n\n<p>Once your post relationship is created, go to the&nbsp;<strong>Toolset&nbsp;<\/strong>\u2192&nbsp;<strong>Post Forms&nbsp;<\/strong>page and create a new form. The usage is the same for forms that create new posts and the ones that edit existing posts.<\/p>\n\n\n\n<p>When you create a new form, the element for the post relationship will be a part of the form by default.<\/p>\n\n\n\n<p>If you need to insert the parent selector field manually for existing forms, go to the&nbsp;<strong>Form Editor&nbsp;<\/strong>section and drag-and-drop relationship in question to desired location.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"451801c8a49e3af4102b5729676a2493\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-form-inserting-the-parent-selector-manually.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-form-inserting-the-parent-selector-manually-500x322.png\" alt=\"\" class=\"wp-image-1732113\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Adding relationship fields to the form using the drag-and-drop editor<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>That\u2019s it! Now, when users create new posts and select their parent posts, the posts will be connected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-forms-when-a-parent-post-is-preselected\">Creating Forms with a Parent Post Preselected<\/h2>\n\n\n\n<p>When using forms to create child posts, the parent post will often be known. For example, you might have a button to add an Event to a Venue currently being displayed, as shown in the following example.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"6f3f6b4c409f31aace055f4b9314b18f\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-cred-creating-child-posts-for-known-parent.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-cred-creating-child-posts-for-known-parent-500x387.jpg\" alt=\"\" class=\"wp-image-1732123\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Venue post on the front-end with a link to a form for adding Events to the post<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>Follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Edit the Content Template for the parent post type (i.e. Venue).<\/li><li>Insert the Toolset <strong>Fields and Text<\/strong> block and inside its editor, click the <strong>Forms<\/strong> button.<\/li><li>In the pop-up dialog, click <strong>Create Child Post Link<\/strong>.<\/li><li>Another dialog appears where you have to select the options for your link.<\/li><li>In the <strong>Parent post <\/strong>section, make sure to select the option <strong>Set the parent according to the currently displayed content<\/strong>.<\/li><\/ol>\n\n\n\n<p>That&#8217;s it! Now, when a user clicks to add a child post, the form will automatically select the parent.<\/p>\n","protected":false},"author":4341,"featured_media":1734717,"template":"","related-lesson":[8469,8429],"class_list":["post-1727299","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-post-relationships","related-lesson-post-forms"],"_links":{"self":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson\/1727299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson"}],"about":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/types\/course-lesson"}],"author":[{"embeddable":true,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/users\/4341"}],"version-history":[{"count":6,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson\/1727299\/revisions"}],"predecessor-version":[{"id":1776717,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson\/1727299\/revisions\/1776717"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/media\/1734717"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/media?parent=1727299"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/related-lesson?post=1727299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}