How To Link Two Post Types - Linked Post Types

Written by the Divi Engine Documentation Team

Introduction

Follow these steps to learn how to link two Post Types.

Description

How to link your two Post Types.

Difficulty

Hard

Time

30 Minutes.

Step 1: Set It Up - Create Two Post Types

Start off by creating two Post Types. In your head, assign one to be the first and the other to be the second. In this example, the Post Types are Food and Shops. The first Post Type is Shops and the second is Food. 

1.) Create two Post Types in Divi Machine.

Step 2: Set It Up - Create Two Field Groups 

Create two Field Groups, one for each Post Type.

1.) Create two field groups.

Step 3: Set It Up - First Post Theme Builder "All" Template 

Set up the Theme Builder "All" template for the first Post Type. In this example, it is the Shops All template.

1.) Add the ACF Item module to the Theme Builder "All" template of the first Post Type. In my example, this is the Shops template.

Step 4: Set It Up - Second Post Type Theme Builder "Archive" Template

Set up the Theme Builder "Archive" template for the second Post Type.

1.) Add the Archive Loop Module to the Theme Builder "Archive" template of the second Post Type. In this example, it is the Food Archive template.

Step 5: Customize Settings - Add Post Object Field

Go to the Field Group of the first Post Type and add a Post Object field named after the second Post Type.

1.) Add a Post Object field to your first Post Type naming it after the second Post Type. In this example, the second Post Type is Food and so I call the field Food (Food LInked for my convenience).

Step 6: Customize Settings - Link The Second Post Type Posts To The First Post Type Posts

Go to each post of the first Post Type and add a linked post from the second Post Type.

1.) Assign any number of second Post Type posts to each first Post Type post. In this example, I assign the "Carrots" second Post Type post to the shop since it sells carrots.

Step 7: Customize Settings - First Post Theme Builder "All" Template

Customize the ACF Item module in the first Post Type theme builder "All" template.

1.) In the Main Options section, select the ACF Post Object field made earlier on in this example.

2.) In the Relational Field Settings select the Custom Loop Layout made in the Divi Library.

Step 8: Customize Settings - Second Post Type Theme Builder "Archive" Template

Customize the Archive Loop module in the second Post Type theme builder "Archive" template.

1.) Select the first Post Type as the Post Type. In this example, Shops is the first Post Type.

2.) Select the Custom Loop Layout made in the Divi Library.

3.) In the Loop Options section, select Linked Post as the Display Type.

4.) In the Loop Options section, select the ACF Post Object field made earlier on in this example.

Step 9: Add Custom Code

No custom code here.

Step 10: Conclusion

View both the first Post Type posts and second post Type Archive page from the front to see the linked posts. In this example, my Food Archive page shows a Custom Loop Layout of shops and my single page of each Shop shows a Custom Loop Layout of each associated food.

More Support?

Please email us at [email protected] if you are unable to get Divi Machine working.


Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.