Post relation field
The Post relation field allows you to create relationships between different post types.
As an example, we have the following post types in our site
- Places (Businesses)
We can submit Places and Events in our site as separate post types, but we also want to associate different Places to different Events, for example when a Place that is listed on our site is hosting an Event.
To create this relationship, we can use the Post relation field.
Adding the field
We have edited the Places post type and added the Post relation field
We named the field Select Event
Under Relation type, we selected Has many as we want Places to be able to host many Events
Under Related to we selected the Events post type
We added a custom relation key event-place as a unique identifier for this relationship
Now that we have created the field, in the post submission form for Places post type we have the ability to select Events that are related
Two way relationship
So far, we can pick an Event during Place submission. If we want to also add the ability to pick a Place during Event submission, we can edit the Event post type and add a Post relation field on that post type aswell. (This is optional, not required for the relationship to work)
In the post relation field we pick the following settings:
Relation type: Belongs to one
Related to: Places
Custom relation key: We use the same key event-place. This ensures the two post relation fields are synced and making changes to one affects the other and vice versa.