I need to grab the media tags used for a gallery on a single post. The post is using only a few tags out of the many created on the site already. I only want to list those. Is there a way to do this? I’ve tried using get_mediatags() with the child_of and parent arguments (separately of course) but this only tries to get hierarchical mediatags as far as I know.
An example: Post A has images in a gallery that have tag1, tag2, tag3. There are tag4…up to tag50 on the site.
When I query get_mediatags (or a similar function) I want to be able to specify Post A as the parent post to filter out only mediatags used on that post’s gallery or attachments.
First you should realize that Media-tags like Post tags are NOT hierarchical. Unlike post categories which are.
As part of the plugin I provide the template function the_mediatags() which operates much like the WordPress function the_tags() which will print out a comma-serparated list of tags for the current $post in a Loop.
If instead you want to access the raw PHP list and not the HTML you can call the a WordPress function yourself which is:
$terms = get_the_terms( $id, $taxonomy );
Where $id is the post ID and $taxonomy would be ‘media-tags’ or better just MEDIA_TAGS_TAXONOMY which is a define for ‘media-tags’. The terms returned would be an array of media-tag terms. You would then need to write your own code to loop through this array and output your term in whatever format.