Hi, I want to display all items (pages) which are associated with a choosen taxonomy term.
What I am trying to do in detail: I have a custom post type “Actors”. And I have movie pages with a taxonomy “actors”, where I add all actors as taxonomy terms who act in the movie. Let’s say it’s a western and one actor would be John Wayne, so I would add the taxonomy term “John Wayne”.
Now, adding a new cpt Actors post “John Wayne”. In this post (beside some bio data) I want to display all movies/movie pages (title and thumnail), where I added the taxonomy term “John Wayne”.
I created a taxonomy field on the cpt “Actors”. I can choose the taxonomy “John Wayne” (or whatever actor term I am looking for), but I only get the term “John Wayne” displayed, not the movies which are associated with the term “John Wayne”.
I feel I am on the wrong track. Is it not possible to do this with the taxonomy field? May I use an other ACF field instead? I could not find an answer in the documentation/forum. How would you guys do this?
Instead of using two separate things for actor, post type and the taxonomy, you can use the custom field with ACF in movies and set the rules as “Post Type” equal to actor, then you don’t have to enter the actor names twice.
Also querying will become easier, because both of them will be linked to each other.
And then what you can do in the actor page is loop through the movies and use ‘get_field’ to find out which movies a particular actor is connected with.
Hey Patrick, thanks for your reply.
I don’t get what you mean with “you don’t have to enter the actor names twice”. I think, there is a missunderstanding.
I have only ONE taxonomy term with the actor name. It belongs to the pages, which I use for movies. I add the taxonomy terms for “actor” only on the movie pages via a meta box.
On the other hand I have a CPT called “Actors”, where I create profile posts of all actors, (Actor name as title/slug) – but here I DON’T have a taxonomy/meta box called “Actors”. On the actor cpt post (in the example above it would be a post with the title/slug “John Wayne”) I only grap the existing taxonomy term “John Wayne” (the one I have added on all movie pages where John Wayne is in the cast) via the ACF taxonomy field, to show all movies, where the taxonomy “John Wayne” was added/choosen in the meta box of the movie page. Only ONE taxonomy term “John Wayne” exists and belongs to the (movie) pages.
But the last step does not work. I can only display the taxonomy term (which is in this case totaly pointless), but not the movies where the term was added/choosen/associated.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.