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 in CPT fields settings to allow posts linking.
- Create two Custom Post Types you want to link. Example: Events and Venues.
- The Events will be added to the Venue in our example. To enable that, go to Events > Settings > Custom Fields and click on Link Posts: Venue on the left hand side to add the custom field to the list on the right hand side.
- Customize the field as required:
- Open advanced settings by clicking on Show Advanced 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:
Setup Link Posts Tabs
Setup blocks in CPT tabs settings to display linked posts on frontend.
- Go to Venues > Settings > Tabs > Select Shortcode and setup GD > Listings shortcode to display linked Events. In GD Listings setup, select Linked Posts > Linked from current post.
[gd_listings post_type="gd_event" post_limit="2" linked_posts="from" sort_by="event_dates_asc" layout="2" with_pagination="1" bottom_pagination="1"]
- Go to Events > Settings > Tabs > Select Shortcode and setup GD > Listings shortcode to display linked Venue. In GD Listings setup, select Linked Posts > Linked to current post.
[gd_listings post_type="gd_place" post_limit="5" linked_posts="to" sort_by="latest" layout="0" with_pagination="1" bottom_pagination="1"]
Linking the Posts
Link one post to another posts from add/edit listing page. Users will now be able to search for Venues and link the Event to the selected Venue, when they add/edit an Event.
Display Linked Posts
Linked posts are displayed on frontend via GD > Listings block which is setup in CPT > Settings > Tabs.
Display Linked Events on Venue
GD > Listings block is setup under Venues > Settings > Tabs to display all the linked Events to the current viewing Venue.
Display Linked Venue on Event
GD > Listings block is setup under Events > Settings > Tabs to display linked Venue to the current viewing Event.