This example uses the Doctor And Location Example (DALE).
In this example the DALE Setup Simple will be created. This setup is used as a base for multiple examples for questions.
• Creating Custom Post Types with CPT UI
Create two CPT UIs: Doctors & Locations. I also removed the Editor on both for a better view.
• Creating an ACF Group for the Doctors
I named the group “Doctor Relation”. As the ACF example provides the Doctors should have a Location relationship, which I named Locations of Doctor/locations_of_doctor. The location where this group should be shown is the “Doctor” CPT UI, which we created in step 1.
Here the setup of the relation field, where we select the “Location” post type which we created in step 1. This will allow us to chose multiple locations for each doctor!
And dont forget to enable the REST API field in the Field Group Settings, so the group can be found and used.
• Creating content for the post types of Doctors & Locations.
For each of those post types I created 5 posts each. I used a [Post Type Name] [Number Of Doctor] format to keep it simple.
The Location posts should simply have a name, while the Doctors have an additional field for relations. I gave each Doctor some random locations. I allso mixed the order of some of the chosen locations, this is for a later Query Relation Order example.
Here is a list of my Doctors and which Locations each of them has.
• Create a normal page named “Doctors”
• Now let us fill that page with content
Here a screenshot of my navigator, for the selection of blocks I used.
For the Query 1 I used the Doctors post type.
For the heading in the query 1 I set the dynamic content to the WordPress post title.
For the Query 2 I used the locations post type.
For the heading in the query 2 I set the dynamic content like before to the WordPress post title.
Now SAVE and refresh the page. You should see some crude doctor and location mix.
If you add a little style to it you can get something like this:
To only display the Locations of each Doctor check out the answer section: DALE: Posts: Only display selected posts of an ACF relation (Dynamic).
If you have comments or questions to this topic please leave a reply. For other DALE related questions please visit the the DALE post.