Home › Forums › General Issues › Get taxonomy name from 'Taxonomy' field and insert into custom loop as category? › Reply To: Get taxonomy name from 'Taxonomy' field and insert into custom loop as category?
I’m not sure if I’ve over complicated things here or not but I have tried your code above replaced the taxonomy name with my own taxonomy and have set on the ACF field, save and load terms to yes and I have return value set to Term ID but I just get a posts not found message. I have double checked that I have selected the correct category in the Taxonomy field on the edit page screen and double checked I have posts associated with that category but still shows posts not found.
I tried returning post object, as well as a mixture of save and load terms…
Little confused by your last message but again it may be me not explaining it correctly so I will do my best below to outline exactly what it is I am trying to achieve.
I have a custom post type with custom taxonomies (categories and tags). This is all working correctly no problems here I can get them to display in a loop perfectly as well.
This CPT is called ‘Exercise Database’, I then have 2 taxonomies associated with it:
Inside Exercise Categories, I have created 10 different categories for different body parts. Chest, back, abs… and so on.
I have also created a separate ‘Page Template’ called ‘Exercise Category Template’, this has nothing to do with necessary CPT files ‘single-‘, ‘archive-‘ and ‘taxononmy-‘. This is a theme based template that can be used on multiple pages via the add pages screen.
The reason I need this page template is because: For each body part (category within the taxonomy) I need a separate page of information as well as the ability to only display exercises for that part of the body. I don’t want chest exercises on the back page. I only want to show the posts with the category of chest for the chest page.
Hence my need for the custom loop because I need to pass the ‘back’ category from the custom taxonomy ‘Exercise Categories’ into the page that I have about back exercises. This is the same for each of the 10 pages.
So I used the ‘Taxonomy’ ACF field so that I could hopefully insert the correct category back, chest or whichever one I needed into the loop and then the page only shows the posts from whichever category I have selected.
Hopefully this will give you a thorough understanding of what I am trying to achieve, I am sorry I have only just started working with PHP but hopefully this will help!
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!
© 2022 Advanced Custom Fields.