Toolset features a special custom field called Post Reference. You can use it to connect two posts. Once connected, when displaying one of these posts, you can display the data for the other related post.
For example, you might connect an “event” post to an “announcement” post. When you display an event post, you can also easily display fields that belong to the related announcement.
The post reference field is added to a group of custom fields just like any other custom field, on the Toolset -> Custom Fields page.
Create a group of fields, or edit an existing one, click on the Add New Field button and select the Post Reference field. Please note that you can only add a post reference field to a group that is assigned to one particular type of post.
Besides the usual custom fields options, you have to select a type of post that the post reference field will be able to connect to. Our example illustrates editing a group of fields that will appear on the events posts, so we want the post reference field to connect to the announcements post.
When we edit any event post, there will be a box allowing us to connect this event to any announcement post.
Now that we have created our reference field we can display any information from the connected post. We can display this information anywhere we need to. For example, this could be a template for single posts (i.e. “Template for Events”) or on an archive page (i.e. for “Events Archives”).
- Use the Fields and Views button and select any post information you would like to display.
- In the insertion dialog, click on the Post selection tab and select to display data for A post related to the current post, set by a Types post reference field.
- Select the Post Reference field you created.
Now, along with the fields of the current post, our template also displays information from the connected post. In our example, we display a title with a link to the related announcement post.
As we have seen above, you can use the post reference field to connect one post to another. But what if you want to connect your post to more than one post? In this case, it is fair to assume you would like to make the post reference field repeatable, which will then allow you to connect one post to multiple posts.
However, a repeatable post reference field implies creating a many-to-many relationship. For example, an event could be connected to many announcements and single announcement could be connected to many events.
This is why Toolset does not allow you to make the post reference field directly repeatable. Instead, it offers to automatically turn your post reference field into a post relationship.
To do this, edit the field group containing your post reference field, edit that field, and click the I need this field to repeat link.
A pop-up dialog will appear, suggesting you need to use a many-to-many relationship. You can click on the Preview change button to get an overview of the necessary changes in the relationship.
If everything looks good, you can click on the Make this change button. Types will then automatically create the necessary post relationship and remove the Reference Field from the group.
That’s it, you will now be able to connect as many posts as you want. Visit our dedicated documentation page to learn how to display information from posts in a relationship.