{"id":736,"date":"2025-03-24T14:27:32","date_gmt":"2025-03-24T14:27:32","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-to-link-two-custom-post-types\/"},"modified":"2025-08-22T10:28:07","modified_gmt":"2025-08-22T09:28:07","slug":"how-to-link-two-custom-post-types","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/custom-post-types-extension\/how-to-link-two-custom-post-types\/","title":{"rendered":"How to Link Two Custom Post Types?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>Linking custom posts types is an awesome feature that can level up your directory. It helps to link one, or multiple custom posts types together to setup blocks like <strong>All Events at a Venue<\/strong>, <strong>All Doctors in a Hospital<\/strong>, <strong>Jobs to a Business<\/strong> etc by linking CPTs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setup<\/h2>\n\n\n\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">This feature requires the <a href=\"https:\/\/wpgeodirectory.com\/downloads\/custom-post-types\/\" target=\"_blank\" rel=\"noreferrer noopener\">Custom Post Types<\/a> addon is installed and active<\/span><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Setup Link Posts Field<\/h4>\n\n\n\n<p>Setup fields in CPT fields settings to allow posts linking.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create two Custom Post Types you want to link. Example: <strong>Events<\/strong> and <strong>Venues<\/strong>.<\/li>\n\n\n\n<li>The Events will be added to the Venue in our example. To enable that, go to <strong>Events &gt; Settings &gt; Custom Fields<\/strong> and click on <strong>Link Posts: Venue<\/strong> on the left hand side to add the custom field to the list on the right hand side.<figure><img loading=\"lazy\" decoding=\"async\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" srcset=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-5HT5Mu6Xeq.png 456w, https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-5HT5Mu6Xeq-300x74.png 300w\" width=\"456\" height=\"113\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-5HT5Mu6Xeq.png\" alt=\"\"><\/figure><\/li>\n\n\n\n<li>Customize the field as required:<figure><img loading=\"lazy\" decoding=\"async\" sizes=\"auto, (max-width: 569px) 100vw, 569px\" srcset=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-WdEOlf2VkH.png 569w, https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-WdEOlf2VkH-300x96.png 300w\" width=\"569\" height=\"183\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-WdEOlf2VkH.png\" alt=\"\"><\/figure><\/li>\n\n\n\n<li>Open advanced settings by clicking on <strong>Show Advanced<\/strong> to choose if a new Event can be added to Venues of other users, or if Events can only be added to Venues that are owned by the same user:<figure><img loading=\"lazy\" decoding=\"async\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" srcset=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-xlMDo9d67M.png 621w, https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-xlMDo9d67M-300x90.png 300w\" width=\"621\" height=\"187\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-xlMDo9d67M.png\" alt=\"\"><\/figure><\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Setup Link Posts Tabs<\/h4>\n\n\n\n<p>Setup blocks in CPT tabs settings to display linked posts on frontend.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to <strong>Venues > Settings > Tabs > Select Shortcode<\/strong> and setup <strong>GD > Listings<\/strong> shortcode to display linked Events. In GD Listings setup, select <strong>Linked Posts > Linked from current post<\/strong>.<pre class=\"wp-block-code\"><code>&#091;gd_listings post_type=&quot;gd_event&quot; post_limit=&quot;2&quot; linked_posts=&quot;from&quot; sort_by=&quot;event_dates_asc&quot; layout=&quot;2&quot; with_pagination=&quot;1&quot; bottom_pagination=&quot;1&quot;&#093;<\/code><\/pre><figure><img loading=\"lazy\" decoding=\"async\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/08\/places-tab-setup-events.png\" alt=\"\" width=\"856\" height=\"681\" \/><\/figure><\/li>\n\n\n\n<li>Go to <strong>Events > Settings > Tabs > Select Shortcode<\/strong> and setup <strong>GD > Listings<\/strong> shortcode to display linked Venue. In GD Listings setup, select <strong>Linked Posts > Linked to current post<\/strong>.<pre class=\"wp-block-code\"><code>&#091;gd_listings post_type=&quot;gd_place&quot; post_limit=&quot;5&quot; linked_posts=&quot;to&quot; sort_by=&quot;latest&quot; layout=&quot;0&quot; with_pagination=&quot;1&quot; bottom_pagination=&quot;1&quot;&#093;<\/code><\/pre><figure><img loading=\"lazy\" decoding=\"async\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/08\/events-tab-setup-place.png\" alt=\"\" width=\"859\" height=\"622\" \/><\/figure><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Linking the Posts<\/h2>\n\n\n\n<p>Link one post to another posts from add\/edit listing page. Users will now be able to search for Venues and link the <strong>Event<\/strong> to the selected <strong>Venue<\/strong>, when they add\/edit an Event. <figure><img loading=\"lazy\" decoding=\"async\" sizes=\"auto, (max-width: 435px) 100vw, 435px\" srcset=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-ZMMXUV1Ykk.png 435w, https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-ZMMXUV1Ykk-300x112.png 300w\" width=\"435\" height=\"162\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-ZMMXUV1Ykk.png\" alt=\"\"><\/figure><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Display Linked Posts<\/h2>\n\n\n\n<p>Linked posts are displayed on frontend via <strong>GD > Listings<\/strong> block which is setup in CPT > Settings > Tabs.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Display Linked Events on Venue<\/h4>\n\n\n\n<p><strong>GD > Listings<\/strong> block is setup under Venues > Settings > Tabs to display all the linked Events to the current viewing Venue.<figure><img loading=\"lazy\" decoding=\"async\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/08\/events-linked-to-place.png\" alt=\"\" width=\"1004\" height=\"825\" \/><\/figure><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Display Linked Venue on Event<\/h4>\n\n\n\n<p><strong>GD > Listings<\/strong> block is setup under Events > Settings > Tabs to display linked Venue to the current viewing Event.<figure><img loading=\"lazy\" decoding=\"async\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/08\/place-linked-to-event.png\" alt=\"\" width=\"993\" height=\"365\" \/><\/figure><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Linking custom posts types is an awesome feature that can level up your directory. It helps to link one, or multiple custom posts types together to setup blocks like All Events at a Venue, All Doctors in a Hospital, Jobs to a Business etc by linking CPTs. Setup Setup Link Posts Field Setup fields [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[213,423],"class_list":["post-736","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-extensions-features","gd_placecategory-custom-post-types-extension"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":3,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/736\/revisions"}],"predecessor-version":[{"id":2155,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/736\/revisions\/2155"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=736"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}