Linked Post Types
Linked post types is something quite powerful. The idea is to link two (or more) custom posts together.
Examples could be:
- Brands (one post type) and Cars (another post type)
- Music Albums (one post type) and Singles (another post type)
- Writers (one post type) and Books (another post type)
- Estate Agents (one post type) and Houses (another post type)
So, using example 1 above, it allows you to:
- On the single car page - show the brand it is assigned to and ACF items from this brand (like image, name, location etc)
- On the Brands archive page - show all the cars that are assigned to this car.
So how do you do this?
First thing to do is to create your two post types. Use our settings to create the two post types - https://help.diviengine.com/article/70-create-custom-posts
Create the ACF post object field inside the ACF settings for your post type that you want to assign to. For example cars, singles, books or houses. This would be the post type that when you go to the other one, will show all these (the one that is linked to the other).
1) Make sure it is a "Post Object" ACF type
2) Make sure you select the other post type that you want them to assign to. In our example, it is the dealer as we want to assign a specific dealer to a car.
On each of these posts - assign the other post to this one. In our example, on each car settings page - assign the brand that you want to link each car to.
Now the setup is complete. Let's move onto how to display these.
a) Show linked post on the single page
Go to the theme builder layout for the single page for your post type (in our example, Cars) and add an ACF item module
- Create a loop layout for the custom post (Dealer) which you want to use. This will show the information about this linked custom post on another custom post single page. Important!!! - Make sure in this loop layout, you are adding ACF items that are assigned to the linked post type (dealer) and not to the current post (cars)
- Choose the ACF item that you created in step 2 above
- Under the relational Field Settings tab - choose the custom layout you created in number 1 of this list. You can also choose a grid system if you have more than one post type selected (see below)
Now it will show the linked post correctly.
b) Show all posts on the archive page
Now you have done step a - how do you show all the posts that are assigned to another? (all cars linked to the dealer in our example)
- Create an archive template for the custom post in the Theme Builder
- Add the Archive Loop module and choose "Linked Post" in the setting: Post Display Type
- Then choose the Linked post object name (the setting you made in Step 2 above)
- Make sure you choose a loop layout as you would for any archive loop module
After this, on the archive page for this custom post - it will show all the posts that are linked by this "Linked Post Object ACF" you have created.