{"id":1727291,"date":"2020-09-15T12:47:45","date_gmt":"2020-09-15T12:47:45","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=1727291"},"modified":"2020-09-15T12:47:45","modified_gmt":"2020-09-15T12:47:45","slug":"using-post-reference-field-to-set-up-one-to-many-relationships","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/es\/course-lesson\/using-post-reference-field-to-set-up-one-to-many-relationships\/","title":{"rendered":"Using Post Reference Field to Set-Up One-to-Many Relationships"},"content":{"rendered":"\n<p>The Post Reference field allows you to connect only one post of one type to one post of the other type. This means, you&#8217;re pointing from the &#8220;many&#8221; side to the &#8220;one&#8221; side.<\/p>\n\n\n\n<p>For example, you might connect an \u201croom\u201d post to a \u201chouse\u201d post (each room can belong to one house). When you display a room, you can also easily display fields that belong to the house.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"adding-a-post-reference-field\">Steps for Adding a Post Reference Field<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Go to the&nbsp;<strong>Toolset&nbsp;<\/strong>\u2192&nbsp;<strong>Custom Fields&nbsp;<\/strong>page and create a group of fields, or edit an existing one.<\/li><li>Click on the&nbsp;<strong>Add New Field&nbsp;<\/strong>button and select the&nbsp;<strong>Post Reference&nbsp;<\/strong>field. You can only add a post reference field to a group assigned to one particular post type.<\/li><li>Select a type of post that the post reference field will connect to.<\/li><\/ol>\n\n\n\n<p>When you now edit any post of the selected type, there will be a box allowing you to connect it to any post of that related type.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"displaying-fields-that-belong-to-the-related-post\">Displaying Fields that Belong to the Related Post<\/h2>\n\n\n\n<p>You can use the Post Reference field to display related post&#8217;s fields anywhere you need to. This could be a template for single posts or an archive page.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Edit a Content Template or an archive page.<\/li><li>Use any Toolset block you want to display fields coming from the related posts.<\/li><li>In the right sidebar, select to use a dynamic source and in the <strong>Post Source <\/strong>dropdown, select the <strong>Parent: &lt;post type name&gt; <\/strong>option. Post type name is the name of the post type you connected using the Post Reference field.<\/li><li>Finally, select the exact field you want to display.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"repeating-post-reference-fields\">Repeating Post Reference Fields<\/h2>\n\n\n\n<p>Sometimes you might want to connect one post to multiple posts by making your Post Reference field into a repeating one.<\/p>\n\n\n\n<p>However, a repeating Post Reference field implies creating a many-to-many relationship. For example, an event could be connected to many announcements and single announcement could be connected to many events.<\/p>\n\n\n\n<p>This is why Toolset doesn&#8217;t allow you to make the post reference field directly repeatable. Instead, it offers to automatically turn your post reference field into a post relationship.<\/p>\n\n\n\n<p>To do this, edit the field group containing your Post Reference field, edit that field, and click the&nbsp;<strong>I need this field to repeat&nbsp;<\/strong>link.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"f5658de30eccdbe8e7a4f06d79c5bf7b\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-types-post-reference-field-repeatable-option.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/toolset-types-post-reference-field-repeatable-option-500x497.png\" alt=\"\" class=\"wp-image-1731721\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Selecting a post type to connect the Post Reference field to<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>A pop-up dialog appears, suggesting you need to use a many-to-many relationship. Click on the&nbsp;<strong>Preview change&nbsp;<\/strong>button to get an overview of the necessary changes in the relationship.<\/p>\n\n\n\n<p>If everything looks good, click the&nbsp;<strong>Make this change&nbsp;<\/strong>button. Toolset will automatically create the necessary post relationship and remove the Post Reference field from the group.<\/p>\n\n\n\n<div class=\"tb-fields-and-text\" data-toolset-blocks-fields-and-text=\"360284519b991feb492b582c7d84725f\">That\u2019s it, you will now be able to connect as many posts as you want and <a href=\"https:\/\/toolset.com\/es\/course-lesson\/displaying-related-posts\/\">display information from posts in a relationship<\/a>.<\/div>\n","protected":false},"author":4341,"featured_media":1734709,"template":"","related-lesson":[8469,8403],"class_list":["post-1727291","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-post-relationships","related-lesson-custom-types"],"_links":{"self":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1727291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson"}],"about":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/types\/course-lesson"}],"author":[{"embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/users\/4341"}],"version-history":[{"count":8,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1727291\/revisions"}],"predecessor-version":[{"id":1735455,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1727291\/revisions\/1735455"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media\/1734709"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media?parent=1727291"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/related-lesson?post=1727291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}