This members-only tutorial provides the steps to set up an automatic bidirectional relationship between items of two different post types using the ACF Post-2-Post plugin by John A. Huebner II. We shall then use
to set meta query for filtering the items by the related items of the other post type.
In this example we are going to work with
The related entries can be shown using either Easy Posts or a Repeater.
Event single page:
Venue single page:
If you have not already, use a plugin like CPT UI to register your custom post types.
Install and activate ACF.
Create a custom field group to appear on the
edit screens like so:
Create another custom field similarly to appear on the
Important: You should use the same field name in both the groups for the Relationship-type of custom field. In this example, it is
Install and activate ACF Post-2-Post plugin.
Add/edit the items of
post type and select the corresponding venues.
Selecting Venue 2 and Venue 3 for Event 2 for example, should automatically show (at the least) Event 2 in the Venue 2 and Venue 3 edit screens, thanks to ACF Post-2-Post plugin. Also, if you edit Venue 2 and remove Event 2, Event 2 will no longer show Venue 2. In other words, the related items get automatically updated and are in sync across the post types.
Create a Template that applies to singular Events and edit it with Oxygen.
Add a Section having the usual elements like + Add > WordPress > Dynamic Data > Title and + Add > WordPress > Dynamic Data > Content.
Add another Section having a "Venues" heading.
Add a Repeater below the heading.
Set the WP Query to custom and select
Since you probably want to show all the related venues, set Posts per page to
You may want to set the Order to be ascending by title.
Select a Repeater Div and add elements as you need. In my test site I added post title and the excerpt. To add the excerpt, add a Text component, select all the text > Insert Data button in the top toolbar > PHP Function Return value and insert
as the Function Name.
Add a Code Block above the Repeater.
PHP & HTML:
This is a premium members-only content.
To view the rest of the content, please sign up for membership ($47/month or $499 one-time).
Already a member? Log in below or here.