Support » Plugin: Media Tags » [Plugin: Media Tags] Grabbing tags based upon post attached to

  • 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.

    Thanks for reading this!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Paul Menard


    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.

    Hope this helps.

    Awsome. Now I would like to do just that – return an array of tags – not for the post but separately for each attachment in the post (with a foreach loop). How would I go about it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Media Tags] Grabbing tags based upon post attached to’ is closed to new replies.