Home › Forums › General Issues › Taxonomy field: display pages associated with terms
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.
Hey Patrick, thanks again. After thinking about your answer, I finally understood what you meant. You were so right. Stupid me. 🙂
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.