Is it possible to dynamically connect 2 CPT sharing the same taxonomy without setting the relationship on the Back-end?
CPT1 = “Projects”
CPT2 = “People”
“city” is a shared taxonomy for both CPT
When I show the page of a “Project” that is based in “Tokyo” (taxonomy “city”=”Tokyo”) I want to dynamically show on that page a list of “People” that are available to work in “Tokyo” (taxonomy “city”=”Tokyo”)
I know I can do this setting up the relationship manually on the backend (one by one) but is there any way of doing this dynamically?
Yes, the common taxonomy (city) is attached to both CPTs (Project and People). It appears associated to both on the ACF pannel and on the admin menu of both CPTs.
(ACF Pannel setup under “Attach to Post Type” option. All the other options set to default except Hierarchical which was setup to Yes)
So, while it may look like the same taxonomy, the terms added under Project and the terms added under People are not the same terms. They used to be in the past but this was changed in WP 4.2
So, as an example of what you need to do. Let’s say that you are showing a single “Project” post. You need to get the “City” term(s) associated with the project and then do a WP_Query() to get the posts from “People” using a tax_query.