So I have two custom post types, Media and Artist. Artists add each image or film as a new post (Media), there is a relationship field for each media post titled ‘Artist’, so when adding an image they select the associated artist.
Another the artist will do is select a category for the media post. This is so that on the artist page when pulling in the artist content, there is an option to then filter based on the Media category.
I can output the categories but the problem is, it shows all categories, regardless if the artist has content for a particular category or not. Is there any way to hide hidden categories and possible hide filters alltogether if there is only 1?
Here is the code I am using to output the category filters:
The problem in the OP is likely due to the fact that artists can share categories, so while one may not have anything in a category others might making them non empty.
There isn’t really any way to do what you want to do directly.
What you would need to do is get all of the media posts related to the artist then loop over all of them to get collect a list of categories and then use this in the “include” argument for getting the terms.
Viewing 2 posts - 1 through 2 (of 2 total)
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