{"id":1727261,"date":"2020-08-19T15:07:01","date_gmt":"2020-08-19T15:07:01","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=1727261"},"modified":"2020-11-03T12:31:33","modified_gmt":"2020-11-03T12:31:33","slug":"many-to-many-post-relationships","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/es\/course-lesson\/many-to-many-post-relationships\/","title":{"rendered":"Many-to-Many Post Relationships in WordPress"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Setting Up Many-to-Many Post Relationships<\/h2>\n\n\n\n<div class=\"tb-fields-and-text\" data-toolset-blocks-fields-and-text=\"360284519b991feb492b582c7d84725f\"><p>To set-up many-to-many <a href=\"https:\/\/toolset.com\/es\/course-lesson\/what-are-post-relationships-and-how-they-work\/\">relationship between posts<\/a>, go to <strong>Toolset<\/strong> \u2192 <strong>Relationships<\/strong>. Choose the <strong>Many-to-many<\/strong> option and follow the wizard to choose the posts to connect.<\/p><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"9f1663376a73363c03383338c57ff2bd\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/setting-up-m2m-relationship.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/setting-up-m2m-relationship-500x308.png\" alt=\"\" class=\"wp-image-1734645\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Setting-up a many-to-many relationship<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>One of the wizard step is to <strong>add fields to the relationship<\/strong>. This option is only available for many-to-many relationships.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"5cb8a63d01b25068c70751b08db1f3a9\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/add-relationship-fields.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/add-relationship-fields-500x322.png\" alt=\"\" class=\"wp-image-1734293\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Adding relationship fields<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>Let&#8217;s look at a few examples to see what this does.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"table\"><tbody><tr><td><strong>Application<\/strong><\/td><td><strong>Connecting<\/strong><\/td><td><strong>Relationship fields<\/strong><\/td><\/tr><tr><td>Event website<\/td><td>Events &lt;&gt; Speakers<\/td><td>Lecture title, time, location, description<\/td><\/tr><tr><td>Recipe<\/td><td>Dish &lt;&gt; Ingredient<\/td><td>Order, quantity<\/td><\/tr><tr><td>Music albums<\/td><td>Albums &lt;&gt; Songs<\/td><td>Track number<\/td><\/tr><\/tbody><\/table><figcaption>Relationship fields in many-to-many relationships<\/figcaption><\/figure>\n\n\n\n<div class=\"tb-fields-and-text\" data-toolset-blocks-fields-and-text=\"09df93215e2515fe782ef1f39dd79be3\"><p><span>When you add &#8220;relationship fields&#8221;, you are creating what we call an &#8220;intermediary item&#8221; for the relationship. This intermediary will hold the custom fields of the relationship. You can display these fields or use them as conditions.<\/span><\/p><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Connecting Related Posts<\/h2>\n\n\n\n<p>After creating a relationship between two kinds of posts, you will see a box at the bottom of the post editor. It allows you to connect between posts.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"752d20f9d1c97787e141beb022e0479b\"><img decoding=\"async\" width=\"817\" height=\"275\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/connecting-related-posts.png\" alt=\"\" class=\"wp-image-1734311\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/connecting-related-posts.png 817w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/connecting-related-posts-300x101.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/connecting-related-posts-150x50.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/connecting-related-posts-768x259.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/08\/connecting-related-posts-805x271.png 805w\" sizes=\"auto, (max-width: 817px) 100vw, 817px\" \/><div class=\"tb-image-caption\"><figcaption>Connecting related posts<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>From here, you can connect existing posts or create new ones that will immediately appear connected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Displaying Related Posts<\/h2>\n\n\n\n<div class=\"tb-fields-and-text\" data-toolset-blocks-fields-and-text=\"360284519b991feb492b582c7d84725f\"><p>With Toolset, it is very easy to <a href=\"https:\/\/toolset.com\/es\/course-lesson\/displaying-related-posts\/\">display related posts<\/a>.<\/p><\/div>\n\n\n\n<p>The most common way to display related posts is when editing a <a href=\"https:\/\/toolset.com\/es\/glossary\/template\/\">Content Template<\/a> of a type that&#8217;s in a relationship. For example, when we&#8217;re designing the template of an &#8220;event&#8221;, which is related to &#8220;speakers&#8221;.<\/p>\n\n\n\n<p>Since it&#8217;s a many-to-many relationship, almost always, you will display related posts using a <a href=\"https:\/\/toolset.com\/es\/glossary\/view\/\">View<\/a>. A View lets you load content from the database and display it as a list, with any styling that you choose.<\/p>\n\n\n\n<p>All you have to do is insert the <strong>View <\/strong>block and in the creation wizard, select which related content it should display.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"4e491e6f25e7a3f48b03743b82c380c4\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/09\/toolset-view-displaying-related-posts.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/09\/toolset-view-displaying-related-posts-500x422.png\" alt=\"\" class=\"wp-image-1770591\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Creating a View for related items (speakers related to an event)<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>Now, proceed to design the View.<\/p>\n\n\n\n<p>In this View, you can also display fields that belong to the relationship. For example, when we list the speakers, we often want to show the titles of their lectures. To display fields that belong to the lecture (the relationship), insert any Toolset block that you want and enable Dynamic Source. Then, in the <strong>Post source<\/strong>, select the relationship. Now, you can choose fields that belong to the relationship.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"956f959a920ac06e58fc44a40d885f5d\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/09\/toolset-post-relationships-selecting-fields-for-intermediary-post-type.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/09\/toolset-post-relationships-selecting-fields-for-intermediary-post-type-500x299.png\" alt=\"\" class=\"wp-image-1770741\"\/><\/a><div class=\"tb-image-caption\"><figcaption>How to select a field of the relationship<\/figcaption><\/div><\/figure>\n<\/div>","protected":false},"author":4341,"featured_media":1734671,"template":"","related-lesson":[8469],"class_list":["post-1727261","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-post-relationships"],"_links":{"self":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1727261","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\/1727261\/revisions"}],"predecessor-version":[{"id":1833189,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1727261\/revisions\/1833189"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media\/1734671"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media?parent=1727261"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/related-lesson?post=1727261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}