WordPress.org

Ready to get started?Download WordPress

Forums

Media Tags
Grabbing tags based upon post attached to (3 posts)

  1. JsonB123
    Member
    Posted 2 years ago #

    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!

    http://wordpress.org/extend/plugins/media-tags/

  2. Paul Menard
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. Thomas
    Member
    Posted 1 year ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags