Media Tags

April 22nd, 2010 @ 9am : 238 comments : Socialize This

All,
I’m working on version 3.0 of the Media-Tags plugin. Specifically I’m working on a Bulk Media-Tags management interface which sits on top of the Media Library system. If anyone is interested in being a beta tester please contact me. Be sure to add ‘Media-Tags Beta Tester’ somewhere on the contact form comment section.

What does the Media Tags plugin do? And why do I need it?

Simply put the Media-Tags plugin allow you assign tags to your uploaded media (i.e. Image, document, etc.) much like the way you assign tags to post in WordPress. The Media-Tags plugin add new fields to the Media Upload popup on the Pages and Posts editor as well as the edit form on the Media Library editor form.

The Media-Tags plugins works by creating a custom Taxonomy using the built-in WordPress Taxonomy support framework. This Taxonomy framework is the same system used by Categories, Post tags, etc. This means the Media-Tags plugin is not creating new database tables in your system or storing tons of data into your wp_options table.

Using Media-Tags to tag media

I know the previous line may seem like I’m talking in circles. Let me explain.

Once you have media items tagged you can access then with some simple PHP functions via your templates like:

1
get_attachments_by_media_tags()

This function takes a number of possible arguments:
media_tags (Required) – This is a comma separated list of tag slugs used to filter the possible selections. At least one media tag slug is required.
media_types (Optional) – This is a comma separated list of media types pdf, jpg, gif, etc.
post_parent (Optional) – This will limit the media items selected to the given post/page ID. Only a single ID can currently be used.
search_by (Options) – default ‘slug’. Allows searching by other methods. At this time only ‘slug’ is supported.
numberposts (Optional) – default ‘-1′. Specify the number of items to return. Works much like get_posts();
orderby (Optional) – default ‘menu_order’. Specify display ordering.
order (Optional) – default ‘DESC’. Specify display ordering.
offset (Optional) – default ’0′. Allow skipping the number of media items returned. Good for handling paging.
return_type (Optional) – default ”. Be default the function returns a raw PHP array. you then need to handle the display of items. Passing ‘li’ will force the function to return the items as an list elements.
tags_compare (Optional) – default ‘OR’. When using multiple elements in the ‘media_tags’ argument this tells the function how they should be compared. For example if you want items that are tagged either ‘vacation’ OR ‘hawaii’. The other possible value here is ‘AND’ to get items that are tagged for both values.
display_item_callback – By default not used. If set this would be a user defined function. A call to this user function will be made for each item found. See the function ‘default_item_callback’ in the plugin file mediatags_shortcodes.php.
call_source – Used internally by the function. Is set when using the shortcode part of the plugin.

An examples of using this function are:

1
2
3
4
$media_items = get_attachments_by_media_tags('media_tags=vacation,hawaii&numberposts=10&return_type=li');
if ($media_items) {
    echo "<ul>". $media_items. "</ul>";
}

Media-Tags uses WP Shortcodes.

I’m sure when reading the above many readers growned about needed to code in PHP. Well the good news is Media-Tags also supports the WP shortcode system. The shortcode equivalent for the previous example would be the following.

1
[media-tags media_tags="vacation,hawaii" numberposts="10"]

When using the shortcode the default output is a ‘li’ for list elements. But you can also use the ‘display_item_callback’ parameter to call a user defined function. Use of the shortcode also provides more parameters that let you control the output.

before_list (Optional) – default is ‘<ul>’. Using this parameter you can pass in your own list wrapper ‘ul’, ‘ol’ and provide needed CSS class and ID settings.
after_list (Optional) – default is ‘</ul>.
post_parent (Optional) – here the value ‘this’ can be used to designate the current global post/page ID.

Pretty cool!

Template function

The Media-Tags plugin also supports a wide range is available template function you can use in your theme templates. For example to list out the Media-Tags tag cloud which is very similar to the Post tags tag cloud you would add the following to your sidebar.php

1
mediatags_cloud();

This template function is actually just a wrapper around the WordPress built-in wp_tag_cloud function. As part of the wrapper we specify using the Media-Tags Taxonomy instead of the default Post tags. To find out what options are available for the mediatags_cloud function just follow the information for wp_tag_cloud.

Another handy function is ‘get_mediatag_link’. This function takes one required argument. The argument is the ID of the Media-Tag. This is link the Category or Tag ID.

Yet another function is ‘the_mediatags’. This function is patterned after the ‘the_tags’ function provided by WordPress. The ‘the_mediatags’ function will output a comma-seperated setup of values for the current post item.

Look for a complete template functions reference coming soon.

Media-Tags Permalink Base

The Media-Tags plugin allows you to setup archives to display the tagged media items. Think of this similar to Category, Tag or Author archives. By default the Media-Tags plugin assigns a special URL parameter where you pass in the Media-Tag slus like ‘http://www.yoursite.com/media-tags/‘. This means if you want to allow someone to view all media items tagged with the Media-Tags slug of ‘vacation’ the URL would be something like http://yoursite.com/media-tags/vacation. Or of you are not using permalinks, Media-Tags will handle the URL as something like http://yoursite/?media-tag=vacation You can also change this ‘/media-tags/’ URL parameter to something of your liking like ‘/gallery/’. To do this log into wp-admin and go to the Permalinks page under Settings. At the bottom of the page you will see the input field for Media-Tag. Simply enter your preference and update the page.

Media-Tags Archive Templates

As mentioned the Media-Tags plugin allows for display of tagged media items in an archive much like Categories, Post Tags and Authors. To support this Media-Tags also support the use of specific theme template files for displaying media-tag items. Following the built-in WordPress template hierarchy when you view an archive if the archive.php theme file is present it will be used instead of the index.php. With the Media-Tags plugin if you have a file in your theme folder named ‘mediatag.php’ it will be used before the archive.php or index.php. Also you can define a specific Media-Tag archive to control the display on a specific Media-Tag ID. For example you want your media items from Media-Tag 12 to look different. You can create a theme file ‘mediatag-12.php’ to display those items differently than the normal media items.

Media-Tags Archive RSS Feed

As part of these Media-Tags archives you also have available an RSS feed which will allow users to add to their feed reader to track new information you tag using Media-Tags. Following the previous example on the archive for media items tagged as ‘vacation’. The archive URL will appears be default as http://yoursite.com/media-tags/vacation The RSS2 feed for this Media-Tag item will be http://yoursite.com/media-tags/vacation/feed/

Export and Import

Since Media-Tags works using the built-in Taxonomy system provided by WordPress it also handles the export of your Media-Tag information via the Tools -> Export options under wp-admin. This allows you to transfer you site content via the WordPress Export process to another WordPress instance where you can import the XML file.

Widgets

The Media-Tags plugin does not contain or support widgets itself. But other developers have put together some Widgets you can download and play with. Note these Widgets depend on Media-Tags being installed.

Download

As is customary the only place you should ever download released plugins is via the WordPress official plugin repository.
Download the new Media-Tags plugin

You can leave a response, or trackback from your own site.

238 Responses to “Media Tags”

  1. Carlos Says:

    Thanks for your work on this new release! Unfortunately, I’ve been unable to get shortcode working… I want to show all the picture attachments for a person on his post, so I use this syntax:

    [media-tags media_tags="person-name" before_list="" after_list=""]

    And nothing happens. Am I doing something wrong?

    Also, on the media tag admin page, when I click on the number of attachments I get nothing, like there were no one.

    Again, thanks for your work and I hope the plugin ends up working for me too ;)

  2. Paul Menard Says:

    Carlos Will look into the shortcodes ASAP for you. Can you tell me what version of WordPress you are using?

    As far as the number count on the new Media Tags admin interface this is the number from WP on the number of items with that tag. In the core WP this Taxonomy is tied to Posts and should take you to the Post listing page in wp-admin. The problem I can’t seem to solve with the number is that in the media-tagd world the count is Posts and Pages. I might just remove the link. I left it originally because it provides and indicator to the user how many times a media tag is used. Thus facilitating deleting dead media tags.

  3. Carlos Says:

    Hi Paul. I’m using the latest, WordPress 2.8.2. And regarding the number count link, do what you think is best. Thanks a lot for the quick answer.

  4. Ken Hobson Says:

    Hi Paul
    Firstly – Great Plug-in
    I “Think” it is exactly what I am looking for, so I can categorize downlaodable documents.

    I am a TOTAL Newbie (learn from a lot of trial and error). Do you have an example mediatags.php file that I can look at to learn how to modify my own?

    Thanks Paul
    Cheers
    Ken

  5. Paul Menard Says:

    @Ken Hobson: If you take the default theme archive.php and copy it to mediatag.php in your current theme folder you should have a good start. There are no special tags needed for the template file. Just your normal loop function.

  6. Paul Menard Says:

    Just pushed version 2.1.1 of Media-Tags to the WordPress repository. This new version (second one today) fixes a set of bug with the relative paths used to load the needed JavaScript libraries when WordPress is not installed into the site root.

    Thanks to Ilan Y. Cohen for pointing out the error and providing suggestions on this fix as well as some other related modifications.

  7. Francisco Ernesto Teixeira Says:

    Hi, I have only a trouble.

    When I’m using this new taxonomy, it’s only working when I’m logged on my wordpress blog. When I logoff and try to access (for example: http://www.virtual.ufpb.br/wordpress/media-tags/biblioteca/) it’s saying that not found. :/

    Anyway, thanks!

  8. Matthijs Says:

    I want the use the thumbnails and the link behaviour of the default [gallery] shortcode for a set of images I tagged with media-tags. I am already spending 4 hours to find a decent solution for this. I don’t think Media Tags can help me with this. No parameter displaying thumbnails or define link behaviour.

  9. Paul Menard Says:

    @Francisco Ernesto Teixeira: Strange. Yes I just tried this on a fresh WP 2.8.2 install with a handfull of media-tag entries. Confirmed that this causes the 404 to be display. Ok. tracing the code. Hope to have a new patch up soon. Thanks for bringing this up.

  10. Paul Menard Says:

    @Matthijs: Hmm. Have not thought about integration on interplay with the WP gallery code. When I have some time I’ll try and find a suggestion.

  11. Paul Menard Says:

    Just pushed a new version of the media-tags plugin, 2.1.2 to the WordPress repository. This should solve the issue reported by Francisco Ernesto Teixeira http://www.codehooligans.com/2009/07/15/media-tags-20-released/#comment-42663

  12. Jozik Says:

    Hello, like to say – it’s very nice plugin.

    Few bugs that occured to me:

    When gallery is searched it is done by //$get_terms_args['search'] = $search_term;

    so slugs and NAMES dont match, cause $search_term is slug, and ['search'] do it by name

    I got around with: $get_terms_args['slug'] = $search_term;

    #2

    It appears that if media-tag slug is same as some categories slug – $term_id in TERM_TAXONOMY will be the same as categories (wrong), so it can’t be filtered right.

    What do you think would be quick fix for that?

    Maybe prefix to slug?

    Thanks, I appriciate your work.

    Jozik

  13. Paul Menard Says:

    @Jozik: Thanks for the comment. I’m not really sure where I pulled the get_terms_args['search'] from. Must have been some other plugins I was looking at. You are correct the correct parameter should be ‘slug’.

    I’m not sure on the second item. Will need to research.

  14. Carlos Says:

    Paul, et. al,

    This is a great plugin, and it’s theory should be integrated into the WP core — really great work.

    One question, though:

    On my mediatag.php archive page, how do I get the title of the current viewed tag to automatically appear?

    e.g., at the top of the page I want it to say, “Images tagged as [dynamic name of media-tag requested]“.

    For normal tag or category archive pages, there is a function, single_cat_title() and single_tag_title()

    For now, I am just parsing the URL and extracting the title from there, but it’s not a pretty solution.

    Once again, thank you!

  15. Paul Menard Says:

    Carlos: Excellent question. Guess I forgot that in the template functions. Here is a little code snippet. I’ll be included this change in the next release next week of the Media Tags plugin. Thanks Carlos for the comment and suggestion.

    Please add this to the bottom of the media tags file ‘mediatags_template_functions.php’.

    function single_mediatag_title()
    {
    $mediatag_var = get_query_var(MEDIA_TAGS_QUERYVAR);
    if ($mediatag_var) {
    $mediatag_term = is_term( $mediatag_var, MEDIA_TAGS_TAXONOMY );
    if (isset($mediatag_term['term_id'])) {
    $media_tag = &get_term( $mediatag_term['term_id'], MEDIA_TAGS_TAXONOMY );
    echo $media_tag->name;
    }
    }
    }

    Then you can call if from your mediatag.php template file like this (Or add the code to your archive.php provided from WordPress):

    Posts Tagged ‘’

  16. Carlos Says:

    Thanks Paul… worked perfectly!

    Once again, great work with the plugin… beautifully executed.

  17. Carlos Says:

    Just upgraded to 2.1.3 – everything seems to work fine.

    Thanks!

  18. discounts Says:

    Thank you for your help.

  19. John Turner Says:

    Great plugin , do you have any plans to add a tags col on the main lib page, like post?

  20. Paul Menard Says:

    @John Turner: not sure I follow your message. I do plan to put in a Media Tag Cloud template function possibly this weekend. Does that answer your question? Sorry not sure what you meant be ‘tag col’.

  21. David Radovanovic Says:

    returns the tags without the proper syntax, i.e.

    restoration

    What would be the proper fix for a valid link? Thanks for a very needed plugin!

  22. David Radovanovic Says:
    1
     <a href="http://www.architecturalwebdesign.commedia-tags/restoration" rel="nofollow">restoration</a>
  23. Paul Menard Says:

    @David Radovanovic: That is strange. Appear it is not including the ‘/’ between your domain and the ‘media-tags’ permalink prefix. If you are running the plugin version 2.2 (the latest) you should be able to adjust this under Settings -> Permalinks. The new version of the plugin adds an input field at the very bottom and defaults to ‘media-tags’. Change your value to include the ‘/’ as in ‘/media-tags’.

  24. David Radovanovic Says:

    even with the /media in permalinks, “/” still is missing:

    http://www.architecturalwebdesign.com/?attachment_id=90

  25. Ami Says:

    Just wanted to give you a big thank you! I upgraded to 2.2 with no issues.

    My biggest want and desire would be a way to bulk-manage tags, where we could use the checkboxes on the Media admin page to add to a category.

    Thanks again – fabulous work!

  26. Paul Menard Says:

    If anyone is interested in the details of the solution for David let me know. I’ve patched the plugin code on his site and will include the patch in the next release of the plugin. Don’t really see a point in providing another release this week for such a minor fix. If your site is running the default permalink structure and you use the Media Tags plugin feel free to leave a comment here and I will pass you the changed files. Or just sit tight and wait for the next release.

  27. Paul Menard Says:

    @Ami: Thank for the comment and complements on the plugin. I really do enjoy this plugin there is just so much functionality built into it.

    I’ve been trying to think of some bulk update or bulk assign logic and screen. If you have any suggestions please state them here. Would love some ideas.

  28. Ami Says:

    Hi Paul! You are so incredibly responsive, thank you!

    Two things, first to answer our prior convo: there’s a plugin that does this reasonably well for categories, called batch categories. Here’s the link: http://robm.me.uk/projects/plugins/wordpress/batch-categories/

    Another idea would be on the Media Library screen, you could try to utilize the bulk actions dropdown to do an add to tags, or add a similar dropdown with the existing media tags where the “apply” button works. Sorry if neither of these solutions is possible, it’s just a couple of ideas I had. :)

    Secondly, I went to the permalinks tab and changed it from ‘media-tags’ to ‘galleries’, and it’s still showing the archives at http://www.testsite.com/media-tags/tag instead of http://www.testsite.com/galleries/tag

    Any ideas? THANK YOU!

  29. Ami Says:

    Oh, and one other thing, there’s a plugin called “Simple Tags” that auto-assigns tags to a post based upon words in the post. I wonder if some of that logic could auto-assign media tags based upon words in the file name of the photo? Pie in the sky, I know, but I thought I’d throw it out there!

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

  30. John Says:

    Sorry, let me clarify, If you click on post you’ll see a “Tags” column on the list view, I was wondering if you had any plans of adding a “Tags” column on the Media Library list view. If not, I’ll see if I can add it and contribute the code back.

  31. Paul Menard Says:

    @John: Ah, Yes do plan on doing this eventually. Though not sure the Media list has hooks like the Pages and Posts lists. It’s on my list for an upcoming release.

  32. Brad Touesnard Says:

    Hey Paul,

    I believe there is a small bug in the latest release (2.2). Lines 343 to 349 of media_tags.php should not be commented out, otherwise all posts are returned in the loop.

    Thanks for the plugin, it is excellent.

  33. Luka Birsa Says:

    I’m using 2.2 version of your plugin and I’m having problems with my custom templates. I’ve hacked the site quite a bit and added some extra features with jQuery (1.3.2) and jQuery timers (1.1.3).
    If I activate your plugin, jQuery timers fail to work (“jquery.timer is undefined”), if I deactivate the plugin everything works as it should.

  34. Luka Birsa Says:

    Ok, debuged it – had to move my includes under , since media-tags includes jquery in the head and that fizzles my other plugins. Perhaps you could alert other authors that your plugin needs jquery to work, as I’ve been digging for two days why my functions magically stopped working. (mental note: do a single change at a time, you’ll debug easier:))

  35. Luka Birsa Says:

    blog stripped my:

    …under “wp _ head();” …

  36. Paul Menard Says:

    @Brad Touesnard: Thanks for the comment. Those lines are purposely commented out. In the original version of the Media-Tags plugin the returned items was limited to the related parent post. Since version 2.0 of the Media-Tags plugin by not limited to returning just the items for the given post (in the loop). If you do want to limit the returned items you can pass the ‘post_patent’ argument into the function call to get_attachments_by_media_tags(); or you can use the legacy function (used in pre-2.0), get_media_by_tag() which will automatically set the ‘post_parent’ parameter.

  37. Paul Menard Says:

    @Luka Birsa: Thanks for the comment on this. I’m assuming you are referring to jQuery used for the front-end theme view and not the wp-admin view. At first I blew this off until I checked my code. Seems I am including jQuery on the front-end instead of just the wp-admin. This will be fixed in the next release this coming week. Here are the details of the bug.

    If you open media_tags.php and view lines 74-82 you will see the line ‘wp_enqueue_script(‘jquery-form’);’ This is the only reference to jQuery in the entire plugin. The problem is this call is in the wrong place. The ‘init()’ is used by the theme ‘wp_head()’ function so as you are aware this means will insert jQuery into the front-end head. The change I just made was to move the ‘wp_enqueue_script(‘jquery-form’);’ line into ‘admin_init()’ function lines 84-88.

    And just to be clean on this. The Media-Tags plugin does not require jQuery for any display for the front-end of the site. However the plugin does use jQuery for many of the screens in wp-admin. For this jQuery is already included. The jquery-form call is needed on the Media-Tags management screen for the Quick Edit function.

    Finally thanks for the tip/advice on the ‘do a single change at a time, you’ll debug easier’.

  38. Ami Says:

    hi paul! just checked in and wanted to let you know there’s a comment in moderation to go above the one posted as comment #3 now. it has some ideas for you about the tagging. thanks!

  39. Paul Menard Says:

    @Ami: Ah. Yeah didn’t see that one held up. You have now been white listed. :)
    As always thanks for the comments.

  40. Paul Menard Says:

    @Ami: Hmm. Well maybe not. The comment seems to be stuck in my Pending group. Even though I’m approved it multiple time. Argh!!!

  41. Ami Says:

    thanks! looks like it’s there now. :) hopefully the ideas on tagging help!

    any clue on my page permalink not working? i’m happy to hardcode it into the php file if that’s easier, don’t really need the option.

    and also, wanted to let you know i’m going to donate to you for this, you’ve put so much work into it and i’m so appreciative. i don’t have much at this point, but hopefully every little bit helps!

  42. Carlos Says:

    Paul,

    Great update…. many thanks as always.

    Is there any way (be it through additional features, or built into wordpress) to allow people to search through the tags?

    I know I can allow people to search within specific categories or tags with hidden fields in the search form element, (e.g., )

    …but can I filter for JUST media-tags?

    Great work as always!
    -Carlos

  43. Paul Menard Says:

    @Ami: Yes, those suggestions help. I’m looking into the Bulk option today.

    As for your issue with the permalink slug not working it should work. If not open the file mediatags_config.php in the plugins tree. You will see the lines 8-12.

    $mediatag_base = get_option(‘mediatag_base’);
    // Need to come up with validation logic here.
    if (!$mediatag_base)
    $mediatag_base = “media-tags”;
    define(‘MEDIA_TAGS_URL’, $mediatag_base);

    Just change line 12 to be
    define(‘MEDIA_TAGS_URL’, ‘galleries’);

    I’ll do more testing on my end. But as I’ve mentioned to other commenters on this site. My test environment is pretty limited to my laptop and my server. It takes the user community to help with the environment variations. LEt me know if this does/doesn’t work. Be happy to help debug further. P-

  44. Ami Says:

    i had no trouble locating that code and changing it, but no luck with the fix.

    it also appears that the plugin isn’t looking at the mediatag.php template, because i made some changes to it and it’s still looking at archive.php (I did some back and forth testing to confirm).

    i loaded a fresh 2.2 file just to make sure nothing i changed had done it.

    sorry for all of these comments!

  45. Ami Says:

    forgot to add – the testsite.com/galleries finds the mediatag.php template but no posts. the testsite.com/media-tags finds posts but not the mediatag.php template.

    hopefully that helps for you narrowing down what’s going on.

  46. Paul Menard Says:

    @Ami: Hmm. Not really sure. I just tested this myself on my local laptop. Both options work as designed. I have a local WordPress version 2.8.4 with some Flag images used for chat icon. Loaded those and set the Media Tag to ‘Flags’ plus the country France, UK, USA, China, etc. Under Permalinks I have this set to ‘something/frank/galleries’. I’ve setup a new template file ‘mediatag.php’ in the WP default theme folder. which just echos the loop contents. No header or anything. Seems to display as expected. I have to ask this. Are you using Permalinks?

    Not sure what to suggest. Would be glad to look at your site if you are willing to give me admin-level access. Email me off-list if you want with the login info.

  47. Ami Says:

    hi paul! instead of me taking more of your time, let me play around with it for a little while more and see if i can get it working on my own. if it’s working for you it should be working for me!

    am using permalinks. and i’m on 2.7.1 if that makes a difference?

    if you wouldn’t mind emailing me with your email address that would be great, so sorry again for all of the questions!

  48. Paul Menard Says:

    @Ami: First email is paul@codehooligans.com

    Second, I’ve not tested this all the way down to 2.7.1. I know the initial 2.0 release of the plugin worked but have not really tested all the latest features. There may be some expected issues since many of the items are fairly new in WP core.

  49. Ami Says:

    OK maybe that is my issue then! It seems like everything is working except this template issue (which doesn’t *seem* like it would be version-related, but who knows?

    And thank you for the email address! I will keep playing and keep you posted.

  50. Mothmenace Says:

    Great work & amazing plugin! I just updated from the beta version, changed the renamed functions and it’s working perfectly. Thanks again for your work. Best

  51. Media Tags könnten helfen : Wiesel.lu Says:

    [...] verspreche ich mir jetzt von dem Plugin Media Tags 2.0 vom Codehooligan Paul Menard aus Austin, Texas. Google half mir ihn zu finden. Das Prinzip ist ganz [...]

  52. Paul Menard Says:

    @Ami: Hey wondering how you were coming with the Media Tags testing. Things sort of dropped off after we discussed a potential issue with you running WP 2.7. I’ve tested things on my end and everything seems to work correct in my local 2.7.1 instance. Including the Permalinks option.

  53. Carlos Says:

    Paul,

    Is there anyway to allow users to search only through media tags?

  54. Paul Menard Says:

    @Carlos: If you are asking is there a way to intercept the front-facing search in WordPress. I’ve not figured out an acceptable solution for this. But I’m adding it to my list of future enhancements.

  55. Carlos Says:

    Paul,

    That, or to insert a custom search form in the media-tags template page(s).

    Thanks once again!

    (I’m gonna poke around and see if I can find anything for this, but so far I havent had much luck).

  56. Carlos Says:

    to add..

    there are obviously functions within WP that will allow this.

    When you are in the admin screen, and viewing tags, you can search through them. So the work exists, it’s just a matter of creating a proper public interface for it.

  57. Carlos Says:

    Oh man.. I’m an idiot — I was able to do what I want.

    Love WordPress and great work on the plugin, because..

    When in a media tag page, say, /media-tags/beach/
    I can just insert a search form on my custom mediatag.php template page, with the action on the form being the current URL of the page.

    See, WordPress will search through tags via /tagname/tag/?s=search_query_here

    ..then it uses the same mediatags page to display them.

    It works perfectly!

  58. Paul Menard Says:

    @Carlos: OH that is awesome news. Thanks for sharing. I’m sure others will appreciate this contribution. At the very least I appreciate the research on this.

  59. Media Tags plugin for WordPress blogs « CodeHooligans Says:

    [...] Media Tags 2.0 released Recent Comments [...]

  60. noponies Says:

    Hi,

    First off, thanks for a great plugin.

    I’ve got a strange issue, where I’m using the plugin as a means to tag images, then use that tagging to create some simple jQuery galleries.

    To list the available tags I’m using the template get_attachments_by_media_tags(‘media_tags=homepage-gallery’); method. Which is working fine.

    Once I’ve got that, I’m iterating over the result using a foreach loop. Within this loop I’m trying to use the getmediataglink() method, and passing in the id result from the for each loop, $v->ID etc. The getmediataglink() method seems to fail when I pass in a numerical ID. Using the wordpress template method wp_get_attachment_url($v->ID) works fine.

    Am I missing something with the parameter that I should be passing into the getmediataglink() method?

    Cheers.

  61. Paul Menard Says:

    @noponies: You are mixing up the template functions.

    The function get_media_tag_link() is used to return a link for the media tag itself. In your case you have a collection (array) of images (actually post attachments) returned from the get_attachments_by_media_tags() call. To get the link you should use the WP function wp_get_attachment_url()

    The get_media_tag_link() for example is used on the Library -> Media Tags listing. If you hover over a media tag item the quick menu show a ‘View’ link. This link was generated using the get_media_tag_link() call. Also if you display a list of media tags in your sidebar using the function list_mediatags() the media tags items are linked using the getmediataglink()

    Hope this helps.

  62. noponies Says:

    Hi Paul,

    Ahh, yep that makes sense. For some reason I assumed the get_media_tag_link() would return the link to the actual attachment item etc.

    I did end up using the wp method wp_get_attachment_url().

    Anyway, great plugin, really increases the flexibility of wordpress in regards to media elements etc.

  63. Mik Says:

    Hi,
    I don’t get how to use it in my page.php file…
    I tried :
    $mediaTags = get_mediatags(‘media_tags=myTag&returntype=li’);
    echo $mediaTags;
    and I get “Array” in my page… i tried to manipulate it different ways but i failed. Even echo $mediaTags[0]; brakes my page.
    Could someone please give me a code example… ? I try to use it with pdf so I need the title and the url. Thanks a lot.
    Mik

  64. Latest wordpress plugin news – WordPress Plugin Releases for 08/04 | Weblog Tools Collection Customer Reviews | WP Review Theme Test Blog Says:

    [...] Media Tags plugin 2.2 for WordPress Release « CodeHooligans [...]

  65. Paul Menard Says:

    @Mik: Sorry for the delay. Was away for the long holiday weekend. Will need to check this. The call you are making the get_mediatags should work. Will need to test this on my own side. Will be back to you soon.

  66. Paul Menard Says:

    @Mik: Actually I just saw your issue. You have two problems with the function.

    1. First you are calling the wrong template tag. You are calling ‘get_mediatags()’. This is a Taxonomy function similar to the template function get_categories() and get_tags(). I think what you want is to call get_attachments_by_media_tags()

    2. You are using the wrong parameters in the call. Keep in mind you are calling the wrong function. In you parameters you are passing a wrong item. you are passing ‘returntype’. This should be ‘return_type’.

    So if you call this function

    $mediaTags = get_attachments_by_media_tags(‘media_tags=myTag&return_type=li’);

    you should get an unordered list of items returned. Also keep in mind you will need to wrap your <ul></ul> around this output.

  67. Mik Says:

    Thanks Paul, it helped a lot ^^
    It worked but the code wasn’t made to handle pdf files (What I was actually trying to do).
    So I made this and it seems to work fine:
    get_queried_object();
    $postName = $post_obj->post_name;
    //echo $postName;
    $mediaTagsParams = ‘media_tags=’.$postName.’&media_types=pdf’;
    $mediaTagsAtt = get_attachments_by_media_tags($mediaTagsParams);
    if ($mediaTagsAtt) {
    ?>

    ID);
    $attLink = wp_get_attachment_url($Att->ID);
    echo ‘‘.$attTitle.’‘;
    }
    ?>

    I use the page name to get pdf files with the same tag name to facilitate the insertion of pdf files to pages… so you just have to upload files and check the right tag to put it on the page ^^
    Thanks for your great work!

  68. Mik Says:

    ok… my code wasn’t dispalyed well.
    i replaced the arrows by brackets :
    [?php
    $post_obj = $wp_query-]get_queried_object();
    $postName = $post_obj-]post_name;
    //echo $postName;
    $mediaTagsParams = ‘media_tags=’.$postName.’&media_types=pdf’;
    $mediaTagsAtt = get_attachments_by_media_tags($mediaTagsParams);
    if ($mediaTagsAtt) {
    ?]
    [div class="mediaTagsAtt"]
    [ul]
    [?php
    foreach ($mediaTagsAtt as $Att) {
    $attTitle = get_the_title($Att-]ID);
    $attLink = wp_get_attachment_url($Att-]ID);
    echo ‘[li][a href="'.$attLink.'" class="lipdf"]‘.$attTitle.’[/a]‘;
    }
    ?]
    [/ul][/div]
    [?php
    }
    ?]

  69. Separatista Says:

    Hi, is it possible to specify size of pictures with shortcode? I want to show pictures with one media tag in page, but I want to show them as gallery, so it would be very helpfull to specify output (thumbnails with special css class with link to original picture). Thank you for your help… Anyway, great plugin, thank you very much…

  70. Dan Says:

    Great plugin! The backend is seamless, I’m just trying to make the backend display in my theme. It works great in the default theme; media-tags.php overrides just as designed, but it just calls up my post archive when I attempt to display a media tag archive. If I knew where/how the media-tags.php was inserted into archives.php I could probably fix it myself… it might be due to some other code work I’ve done on the theme. I’ll keep experimenting, but if you have an idea of how to do this, your input is invaluable. Cheers!

  71. Dan Says:

    Now I have it working–awesome! I thought the template file would be mediatags.php instead of mediatag.php for some reason. All sorted out–now to trick it! :-)

  72. Paul Menard Says:

    @Dan: Glad you figured it out. Was just about to respond. Yeah the template file is sigular, mediatag.php. You can change this if you edit the mediatags_config.php file where it is defined.

  73. Ami Says:

    hi paul! so sorry for the delay in response – i was on vacation for two weeks. i’m upgrading my test site this weekend to see if the permalink fix works! thanks so much. :)

  74. Dan Says:

    Is there a way to exclude tags from the cloud? I am making use of this plugin to highlight photos under specific categories, but don’t really want those categories to show in the tag cloud at large. Great plugin… redesigning a lot of my site around it.

  75. Paul Menard Says:

    @Dan: Thanks for the comment and kind words about the Media-Tags plugin. Look forward to hearing more about how you are using this plugin on your site.

    As for your question yes there is a way to exclude items from he list. The Media Tags tag cloud function you are calling ‘mediatags_cloud()’ is a basic wrapper to the core WordPress tag cloud function ‘wp_tag_cloud()’. Part of the wrapper code is to set the Taxonomy so you are returned media tag instead of categories or post tags.

    Looking at the WP Codex for the wp_tag_cloud function http://codex.wordpress.org/Template_Tags/wp_tag_cloud there is an ‘exclude’ parameter. This exclude parameter will be the ID of the media tag you want to exclude. Hope this works for you. If not let me know.

  76. Carlos Says:

    Hey Paul,

    I am unable to change the slug/url for established media-tags.

    If I go to Media -> Media Tags -> Edit a tag (or Quick Edit), and try to change the slug, I get an error, “Tag not updated.”

    Everything seems to work fine. Running 2.2.5

  77. Paul Menard Says:

    @Carlos: You are running 2.2.5??? Man, my first and only suggestion at this point it to upgrade to the current 2.8.4. I did not plan to support anything older then 2.7.1

  78. dreb Says:

    Great plugin, but not compatible with WP Security Scan, which overwrites WP Version. Could change the function is_MEDIA_TAGS_URL() ?

  79. Paul Menard Says:

    @dreb: Thanks for the comment. Not sure how the plugin is effected by the WP Security Scan you are referring to. And not sure what you are requesting. Do you want me to rename the function?

  80. CI Says:

    [...] verspreche ich mir jetzt von dem Plugin Media Tags 2.0 vom Codehooligan Paul Menard aus Austin, Texas. Google half mir ihn zu finden. Das Prinzip ist ganz [...]

  81. Separatista Says:

    Hi, is it possible to use this plugin with WordPress MU? My idea: People wrote on their blogs for example about some film and upload pictures with the same media tag. And I want to show all pictures (from all MU blogs) with the same media tag. Thank you for your help…

  82. Paul Menard Says:

    @Separatista: Good news is the Media-Tags plugin is compatible with WordPress MU. The bad news is what you are asking is not possible. In WordPress MU each site is contained in it’s own set of database tables. The Taxonomy queries uses via WordPress core are limited to only a given site. just like with categories and tags you cannot access Media-Tags across all sites within the same WordPress MU engine. Sorry, this is a limit in the WordPress MU core architecture not Media-Tags.

  83. Carlos Says:

    Paul,

    I meant that 2.2.5 was the version of the plugin I was using.

    My WP version is the latest (2.8.4). Sorry about that.

  84. Emeric Says:

    hello,

    sorry for my silly question but i’m totally stuck. when i use the shortcode on a page : that works!

    [media-tags media_tags="exemple?"]

    when i call the function in a template : nothing happen…

    $mediaTags = get_attachments_by_media_tags(‘media_tags=exemple’);

    i really don’t understand…

    any idea? thank you very much.
    All the best from Paris, Emeric

  85. Paul Menard Says:

    @Emeric: Thanks for the comment. Let me try to explain.

    When I first wrote the Media-Tags plugin there was only the template function get_attachments_by_media_tags(); This function returns an array of attachments that match the query criteria. Sometime later I wrote the shortcode handler. When using the shortcode I don’t want to return an array because this will look bad on the output. So when using the shortcode the default return is an unordered list of items.

    If you want the same output as the shortcode when calling the get_attachments_by_media_tags(); function then you need to call pass in another parameter like

    $mediaTags = get_attachments_by_media_tags(’media_tags=exemple&return_type=li’);

    then just echo the returned variable:

    echo $mediaTags;

    Another options- When you pass in the ‘return_type=li’ parameter the media tags code actually calls an internal function to handle the list item output. In the media tags plugin folder. Take a look at the file code for ‘mediatags_shortcode.php’. At the very bottom of this file is a function ‘default_item_callback’. If you want to have more control over the media-tags list item output you can define your own callback function in your theme’s functions.php file. Then pass that function name into the function call. For example let’s say you copied the ‘default_item_callback’ function into you own functions.php theme file and renamed the function ‘my_function’. you would then pass the name of that function in the the media_tags function like this

    $mediaTags = get_attachments_by_media_tags(’media_tags=exemple&display_item_callback=my_function’);

    Note when doing this you will need to provide the outer <ul> elements. This is muck like calling other WordPress functions like wp_list_pages(), wp_get_archives(), etc.

    As always thanks for using the Media-Tags plugin and if you have any problems please met me know.

  86. Jonathan Says:

    Hi

    I wondered if it’s possible to control the size of the images that are displayed when calling media based on tags. Rather than display full size, I’d like it to show a ‘gallery’ of those items.

    Is this possible – have I missed a trick somewheres? :)

    Thanks – great plugin.

  87. Paul Menard Says:

    @Jonathan: Thanks for the comment. Via the Media Tags plugin it is not possible to control the size of the returned images. This is more a design decision on my part than a limitation in the plugin. By using the get_attachments_by_media_tags() function an array of images which match your query are returned. Via that array you can then pull in the thumb, medium, large of full size image yourself.

    My reasoning for not allowing filter of the image size is that I didn’t want to take the next step where people will request something like an image manager that allows cropping and resizing of images on the fly. There are many great plugins out there that already provide this functionality. So I stopped at the management of the image Media Tags logic.

  88. Maxx54 Says:

    Online instructors need to set clear expectations and guidelines for course and discussion participation and use a variety of strategies to assess student learning. ,

  89. Emeric Says:

    Thank you very much for the explanations! Very very helpful! Everything works now :-)

    I wanted to use media-tags to link posts and images. Exemple : show automatically in a post call “exemple” all the images tagged “exemple”. My idea was to call the slug (of media tags) the same as the ID of the post. CAD: All the images media-tagged 51 appear in the post 51. I wrote something like :

    $mediaTags = get_attachments_by_media_tags(’media_tags=$the_id&return_type=li’);

    but that didn’t work and my knowledge in php is limited :-) It could be amazing to have, in the next update, a new option in the post window : “choose your media-tags gallery” and automatically the images appear in the post ;-)

    Anyway, thank you very much for your plugin. It’s already very helful. All the best from Paris, Emeric

  90. Paul Menard Says:

    @Emeric: You are close on your logic. Instead of the Post ID you should match the Post slug to the media-tags slug. If you are using media-tags within the WP loop this should be something like:

    $mediaTags = get_attachments_by_media_tags(’media_tags=’.$post->post_name.’&return_type=li’);

  91. Jaime Chismar Says:

    Hello Paul!

    First, I love this plugin. It is so useful! Thank you!

    Currently, I am using it to display list of PDFs as an archive. Love it!

    Here’s my problem: I want to use this plugin on a password protected site. If I login as a admin, I can see the list of PDFs. If I login as a subscriber, I just get a search box.

    If I take off the password protection, everyone can see the list of PDFs just great.

    At first, I thought it was the password protection plugin, so I tried another one. I got the same result.

    I modified the media-tags URL and got the same result.

    Do you have ANY suggestions? I would be so grateful if you could point me in the right direction.

    Best,
    Jaime

    PS: http://wordpress.org/extend/plugins/members-only/

  92. Paul Menard Says:

    @Jaime Chismar: Hmm that is an interesting issue. I’ll need to setup a test site on my end with that plugin to see if I can determine the issue. I’ve used the Force User Login plugin on client sites and works pretty much the same as the members-only. I’m not sure why WP does not allow subscribers to see the PDFs. Are you running any sort of Roles Management plugin that would override the default subscriber access?

    Technically the media-tags plugin displayed attachments which are child items of the Pages/Posts in your system. Attachments don’t generally have their own access level. They will simply inherit access from the parent Page/Post. Meaning if the parent Page/Post is password protected for example then the attachment will have the same restriction.

    I’ll investigate and email you if I find anything. Interesting concept.

  93. Jaime Chismar Says:

    One final thought… Is there a way to get a media-tag category to display as an RSS feed. That may also solve the problem.

  94. Paul Menard Says:

    @Jaime Chismar: Sure that is already built into the WordPress Taxonomy system. On your site you can access the media-tags archive something like:

    http://yoursite.com/media-tags/

    You just add ‘/feed’ to the end of it like:

    http://yoursite.com/media-tags//feed/

    I don’t think there is a way to do this via template code. Might need to add this in the next release.

    Also, you can change this ‘/media-tags/’ part of the URL by going to your Settings -> Permalinks page. Down at the bottom you can enter whatever value you want to use.

  95. Jaime Chismar Says:

    Hmmm… for some reason this doesn’t show up as an rss feed. I disabled the password protection to show you: http://clients.acg-analytics.com/media-tags/energy-environment/feed/

    I am using the most recent version of WP. All of my other feeds from topics and categories are solid.

    Thoughts? Did I miss a configuration in the Dashboard?

    Best,
    Jaime

  96. Paul Menard Says:

    @Jaime Chismar: Strange. Not sure what is going on. Again, this is handled via WordPress core not the Media-Tags plugin. There is something in your rewrite rules preventing the feed from displaying? What other plugins are you running?

  97. Jaime Chismar Says:

    Good questions:
    1. I did not modify any core functionality, just templates.
    2. I am only using three plugins: Yours : ), KB Advanced RSS Widget, and WP From Email. I deactived the password protection for now.

    Do you have a URL for a working media-tags feed?

    Again, thanks for checking into this. I really appreciate your help.

  98. Paul Menard Says:

    @Jaime Chismar: Ok well geez what does the KB Advanced RSS Widget do? Can you disable the RSS widget to see if this solves getting the media-tags RSS. Also, since we have had so much back and forth any chance I can be granted access to your wp-admin? Email me via the contact form on this site if possible. Thanks.

  99. Loy15 Says:

    My school system was almost entirely white and generally middle class. ,

  100. Stefan Says:

    Would be fantastic if the “Media Search” at …../wp-admin/upload.php would search throw these tags, too. Don’t know if it’s possible to improve this file – search in wordpress with the ability to search throw your media – tags, too?

  101. Stefan Says:

    After quick-editing a tag and try to save the new one:
    Fatal error: Call to a member function using_permalinks() on a non-object in /(……)/wp-content/plugins/media-tags/mediatags_template_functions.php on line 80

  102. Coder96 Says:

    THAT would be a good use of a big carbon tax. ,

  103. Emeric Says:

    Hello,

    Just a little message to tell you since i have updated to 2.8.5 (i made some other changes but I guess it’s because of it), I can’t display listings of media tags like an archive.

    http://www.yoursite.com/media-tags/ = Error 404 :-/

    Anyway, thanks again for the plugin! It’s so useful!
    All the best from Paris, Emeric

  104. Emeric Says:

    http://www.yoursite.com/media-tags/slug-of-my-tag (sorry!) = Error 404 :-/

    All the best from Paris, Emeric

  105. Paul Menard Says:

    @Emeric: Thanks for the comment. Will need to check the plugin in 2.8.5 Things don’t normally change with dot releases. But who knows. Sorry for the late reply. Have been out.

  106. carla Says:

    hello, thanks for the great and useful plugin =)

    I am trying to use compare_tags=AND to combine 2 categories. It works well when there are media in the both categories listed. But when there are no media in the both, or there is a media in only one category, I get a last media added (media in categories not listed too).

    Can you help me please? I am taking a look in your code.

  107. Alex Glover Says:

    I was just wondering if you could explain to me what is actually supposed to go in get_attachments_by_media_tags(); parameters. I know that it is media_tags= but what does that even mean. Is it the post ID, the post name? The media-tag name? the media-tag ID? is there any documentation for this plugin?

  108. Paul Menard Says:

    @Alex Glover: The ‘media-tags’ parameter should be the Media Tag slug.

    For example let’s assume you have media (images) tagged via Media Tags as ‘Tag1′, ‘Tag2′ and ‘Tag3′. The respective slugs for these tags would be ‘tag1′, ‘tag2′, ‘tag3′. OR more complicated a Media Tag ‘Vacation Texas’ would have a slug as ‘vacation-texas’.

    Media Tags follow the same slug rules as Posts, Categories, Post Tags.

    For documentation try reviewing the FAQ http://wordpress.org/extend/plugins/media-tags/faq/

  109. Alex Glover Says:

    Thanks for your speedy reply!!! I got that working, but is there something wrong with the parameters for post_parent?
    $mediaTags = get_attachments_by_media_tags(‘media_tags=juicy-reel&return_type=li&post_parent=’ $child->ID); I even tried putting a number in the place of child->ID and it didn’t work. Any ideas?

  110. Alex Glover Says:

    Nevermind. I figured it out. Just letting you know that in your documentation in the readme.txt, it says post_parent and on your faq page it says postparent.

  111. Paul Menard Says:

    @Alex Glover: Thanks for letting me know that you figured this out. And for others who have the same question. The post_parent is the Post/Page ID not the media tag ID. Think about this. When you upload an image to WordPress it created an association between that item and the Post/Page. So by passing the post_parent you are limiting the search to only media items having that parent ID.

    And Alex, yes I know the FAQ online is ‘postparent’ for some reason wordpress.org removes ‘_’ characters. Have not had time to look into the documentation to get around this. Thanks.

  112. Alex Glover Says:

    Actually I was wrong. I didn’t figure it out. It was apparently displaying ALL attachments that were tagged with that particular tag. Any ideas? Sorry about the storm of posts!

  113. Paul Menard Says:

    @Alex Glover: Alex not know your system or what post/page you are using it’s difficult to provide guidance. Sorry.

  114. Ian Atkins Says:

    Hi,

    Thanks for the plugin, its made my day. It should be core, its so flexible, thanks alot.

    One question, is there a parameter for get_attachments_by_media_tags that allows for negatives, or to get images that are not tagged.

    At the moment I am using the two tags (finishes,techincal) to display two images in different places. There is also a slideshow on the page, which also displays images tagged product.

    Ideally I would like to query for images that are not tagged either finish or technical.

    Currently every image in the slideshow has to be tagged, which a little time consuming.

    Thanks again,

    Ian.

  115. Paul Menard Says:

    @Ian Atkins: Ian that is actually a really nice suggestion. And the first one I’ve had to provide a ‘not’ tagged. Will need to figure out the mechanics of this. Currently as far as I can tell this is not something supported by the WordPress Taxonomy system. Since version 2.0 the Media Tags plugin has used the Taxonomy system for storing tag information to post relationships. This is the same system used for example when you set the category or tag for a post. To my knowledge there is not a way to select the ‘not’ tagged items. But let me work on that. And again great suggestions.

  116. Ian Atkins Says:

    Hi Paul.

    I was thinking of coding it by taking a get_posts query and then comparing the id’s of the results against the media tag query. But I thought that might of been a rather long winded way of doing things.

    I’m not too hot on array’s, but I’ll let you know if I have a stab at it.

    Thanks.

  117. Ryan Says:

    Hey Paul,

    Great plugin. It’s letting me do some cool stuff in tandem with the jQuery Cycle plugin.

    One question: it’s not clear to me how I’d grab the captions, etc. associated with an image. Is this possible with one of the existing functions, or even with some custom code?

  118. Paul Menard Says:

    @Ryan: There current aren’t any hook to all for display retrieval of the caption information via the Media Tags plugin. That is a great idea though. I’ll need to see about including that in the upcoming release.

  119. dreb Says:

    Hi Paul,
    in next release, could you replace the string “wp_posts” by “$wpdb->posts” in the function mediatags_postsWhere (see mediatags_rewrite.php). Otherwise, your great plugin does not work when the database prefix is changed from “wp_” to anything else.

  120. Paul Menard Says:

    @dreb: Yes, definitely! Sorry for missing that. I stole that code from another plugin and didn’t catch the hard-coded table reference.

  121. Ryan Says:

    Thanks for the quick response Paul. I did some searching and it doesn’t seem easy to do this manually; I’m not sure what WordPress functions you’d use to grab that info, but you could be the first person to figure it out!

  122. Paul Menard Says:

    @Ryan: I’m up for that challenge. So question on how you are using the Media Tags plugin. There are two basic way. View the template code or via the shortcode?

  123. Ryan Says:

    Nice :)

    I’m calling the function in the template.

  124. kevin Says:

    @Paul: “By using the get_attachments_by_media_tags() function an array of images which match your query are returned. Via that array you can then pull in the thumb, medium, large of full size image yourself.”

    Could you elaborate on this or point me in the right direction?

    Your media_tags plugin seems to be almost exactly what I need, but I’m stuck. I intend to setup a couple gallery pages that will pull images posted with WP’s built-in media handler. With your plugin, I’ve tagged the images I want pulled into this page “paintings”. Using shortcode on the page [media-tags media_tags="paintings"] pulls in the images I’ve tagged “paintings” successfully, but it’s pulling in the full sized ones. I would like to pull in thumbnails instead and have each of those link to the full-size image. That’s all I want to do (no fancy dynamic resizing, captioning, etc). In your response to a previous question, you allude to this being possible by utilizing the array of images generated by the get_attachments_by_media_tags() function. I’ve searched all over and can’t figure this out. I tried a few gallery-specific plugins, but each one would essentially force me to start over with all of my images that already exist in WP’s media library and in my blog posts. Also, their functionality seems like overkill when all I need is a simple list of images that dynamically grows as I upload new images and tag them with your clean plugin. Thanks for your time!

  125. Nathan Says:

    Like Alex, I’m have trouble with post_parent. Despite setting the post_parent=this, it still pulls in all images site wide with the header tag.

    I’ve tried variations such as =’this’, =\’this\’ etc. and no luck. Only specifying the exact id will it limit it (but I want to keep that id dynamic)

  126. Nathan Says:

    $mediaTags = get_attachments_by_media_tags(‘media_tags=header&post_parent=this&return_type=li’); echo $mediaTags;

    Try it without the php bits at the start and end this time!

    Cheers

  127. Nathan Says:

    I did get it working by doing this, but I’m sure that’s going about it the long way and there’s a trick to getting post_parent=this to work

    $current = $post->ID;
    $mediaTags = get_attachments_by_media_tags(‘media_tags=header&post_parent=’.$current.’&return_type=li’); echo $mediaTags;

  128. Emiliano Jordan Says:

    Sorry, my last post had a typo in the second URL

    http://oregon.cyclingaction.com/images/ryan-trebon/

  129. Toby Says:

    For reference, since I couldn’t find this written anywhere, these are the fields for each item in the array returned by get_attachments_by_media_tags():
    ID
    post_author (id)
    post_date (like 2009-12-02 16:08:08)
    post_date_gmt
    post_content
    post_title
    post_excerpt
    post_status
    comment_status
    ping_status
    post_password
    post_name
    to_ping
    pinged
    post_modified
    post_modified_gmt
    post_content_filtered
    post_parent
    guid (contains url to full-size image)
    post_type (always “attachment”)
    post_mime_type
    comment_count

    If you are using the full sized image, “guid” from this array will give you the URL. If not, you can pass the id to wp_get_attachment_image_src($ID, ‘size_name’), where size can be “thumbnail”, “medium”, “large”, or “full”. This returns an array, of which spot 0 gives the URL, 1 gives the width, and 2 gives the height.

  130. Ryan Says:

    Hey Paul,

    Just an FYI, when I go to Media > Media Tags and do a quick edit, the following error pops up:


    get_attachments_by_media_tags()

  131. Ryan Says:

    I mean…the following error pops up…


    Fatal error: Call to a member function using_permalinks() on a non-object in /homepages/26/d292238976/htdocs/wsb5417974701/wordpress/wp-content/plugins/media-tags/mediatags_template_functions.php on line 80

  132. Ryan Says:

    Paul,

    Last comment — just wanted you to know I figured out my last problem. The docs are unclear on how to use the template function; you need to specify the return_type parameter as li or you won’t get anything.

    Thanks for your hard work and a great plugin.

  133. Elderlore » Changement du moteur de blog: bienvenue sous Wordpress! Says:

    [...] la fonction native de bibliothèque Média de WordPress est pratique, surtout avec l’extension Media Tags; [...]

  134. Daniel Says:

    Will this plugin work if attachments are added when creating posts from “QuickPress” on the dashboard or using a desktop app like MarsEdit?

  135. Paul Menard Says:

    @Daniel: I’m not familiar with the way these third-party application function in regard to adding attachments for a Post/Page. I’m assuming these application function just as if you are adding the attachments via the web wp-admin interface.

  136. Kim Flournoy Says:

    Is there a way to test if a given image has a media tag? I have a function that returns an array of images, and I want to iterate over that array and see if there are media tags associated with the image. If there’s not already a function for this, can you tell me where the tag information for the image is stored in the database, and I’ll add that to the sql statement? Thanks!

  137. Paul Menard Says:

    @Kim Flournoy: Actually no need to resort to your own custom SQL. As of 2.0 the Media Tags plugin uses the WP Taxonomy system. This is the same system used by post categories and tag.

    So to check if a given image has media tags you should simply need to call

    get_the_terms( $id = 0, $taxonomy )

    The id is the post id of the image. The taxonomy is the media-tags taxonomy which is ‘media-tags’ or use the define MEDIA_TAGS_TAXONOMY which is set in mediatag_config.php

    Give that a try and let me know.

  138. Kim Flournoy Says:

    Yup, that was the missing piece of the puzzle. Thanks so much – Happy New Year!

    -Kim

  139. Frances Leyland Says:

    Hi Paul

    I am very keen to use media tags as it is just what I need.

    But installation leads to a number of php errors in my worpress installation – which is 2.9.

    These include: Undefined index: activate in media_tags.php on line 76

    Notice: Undefined property: WP_Query::$is_mediatags in mediatags_rewrite.php on line 60

    Notice: Undefined variable: whichmediatags in /mediatags_rewrite.php on line 145

    Undefined variable: update_message in mediatags_admin.php on line 837

    I don’t think this is a plugin conflict as mediatags was the first plugin I installed.

    Are the errors because I am using worpress 2.9?

    Or do you have a rough idea of where the problems might be coming from?

  140. Frances Leyland Says:

    I should have said – despite the errors – Media Tags does seem to be more or less working.

  141. Paul Menard Says:

    @Frances Leyland: Thanks for the comment. Yeah I do have some work to do for the 2.9.x updates. Seems the WP core has more changes. Look for an update soon.

  142. Frances Leyland Says:

    Thanks. Though if you turn off debug, there is no problem. Just looks a bit messy at the moment.

  143. Casey Says:

    Awesome plugin, easy to use, no issues following instructions… but I want to cast my vote for including a tag cloud function… or… do you know of any other tag cloud plugin that can pick up on your plugin’s tags?

  144. Paul Menard Says:

    @Casey: Thanks for the note. And Thanks or the vote. The good news is the Media Tags plugin already supports a Tag Cloud feature. mediatags_cloud(). This function is a clone of the default WP Tag Cloud function http://codex.wordpress.org/Template_Tags/wp_tag_cloud

  145. Enrico Says:

    Good work Paul, this plugin is perfect for my job, but it lacks of documentation, don’t you think?
    Where are public usage guidelines?
    I’m lost reading all this comments!!. :)
    I hope it’ll come soon!

  146. Paul Menard Says:

    @Enrico: Thanks for the comment. The ‘public usage guidelines’? Not sure I follow your question. If you have some specific need just ask. I’ll try and point you to the correct usage.

  147. Enrico Says:

    Thanks Paul, I’m happy to tell you that I found instruction in readme.txt inside of the plugin package!
    Usually I find usage guidelines directly in the official plugin’s web page, so here is my question ;) .
    I’m also glad to let you know that I’ve developed a widget plugin for your awesome new version of Media Tags, because I need it for my job.
    If you want i can share my code with you, maybe it could be included in a next release.
    Let me know, email me if you want.
    Thanks.

  148. Paul Menard Says:

    @Enrico: Nice. Yes, would love it if you shared you Widget code. I’ve also been working in a Widget for the next release but have been behind on some client work (my day job) so have not had much time to finish things. Feel free to email the code to me paul {at} codehooligans {dot} com

  149. Eric Di Bari Says:

    I must say that this plugin was exactly what I was looking for. Thanks for the great work.

  150. Carlos R Says:

    Hi Paul! And again, thanks for your great work.

    I’m going crazy trying to automatise the function of the plugin so it can automatically show all the attachments with a certain tag in the page which slug is the same (as the tag). I’ve figured out this code but it doesn’t work…

    1
    2
    3
    4
    5
    6
    7
    8
    [?php $tagArgs = array(
        'media_tags'    =]  the_slug,
        'orderby'       =]  'date',
        'order'     =]  'DESC',
        'numberposts'   =]  '6',
        'return_type'   =]  'li' ); ?]

    [?php $mediaTags = get_attachments_by_media_tags($tagArgs); echo $mediaTags; ?]

    May someone have already posted the solution, but I have not been able to find it… Anyway, thanks in advance.

  151. Paul Menard Says:

    @Carlos R: Thanks for the comment. Depending on your hosting environment you might be seeing an error. Or if this is a typical live environment you may not since you host will probably disable PHP errors. The only error/issue I see is that the media_tags parameter in your array needs to be enclosed in quotes like all the other values. Let me know if this helps. Thanks.

  152. Carlos R Says:

    Thanks for the swift answer, but the_slug is a custom function to pass the page slug as the media tag, so adding quotes will not help me, because the plugin would search for “the_slug” tagged media…

  153. Paul Menard Says:

    @Carlos R: Guess I’m a little confused as to why you are passing a callback function reference into the media_tags field of the array. First and foremost you cannot pass a bare variable into the array construct. You WILL cause an error. Per the documentation for the Media-Tags plugin (I know they need work) the ‘media_tags’ parameter is to be used for the search media tag. The only function reference allowed is the ‘display_item_callback’ function. If this is defined then the media tags plugin will call it to display the media tag element.

  154. Carlos R Says:

    Ok, so this is not the way, I guess :) What I want is to pass the page slug automatically to the get_attachments_by_mediatags function, so, for example:

    You’re in a page called “Recipes”, which has the slug “recipes”. So I want to show all the media tagged “recipes” to appear automatically, without the need to hardcode the tag each time I create a new page.

    This way, I can have a way to automatise this throught the template. Is this doable?

    Thanks for your interest!

  155. Paul Menard Says:

    @Carlos R: This is totally doable. On a page or the single.php template within the look you have access to the WP post variable post -> post_name. The ‘post_name is the Page/Post slug. So you just need to pass that into the ‘media_tags’ array parameter.

  156. Carlos R Says:

    My real problem is that I don’t know PHP :) Could you please tell me how to pass the variable into the array?

    I also have the code outside the loop, so should I open a new query?

    Thanks again!

  157. Carlos R Says:

    Ok, I got it! It goes like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
            [?php $tagArgs = array(
                'media_tags'    =]  $post->post_name,
                'orderby'       =]  'date',
                'order'     =]  'DESC',
                'numberposts'   =]  '6',
                'return_type'   =]  'li'
                'size'          =]  'thumb' ); ?]
           
            [?php $mediaTags = get_attachments_by_media_tags($tagArgs); echo $mediaTags; ?]

    But now I can’t get the “size” parameter to work. How can I get a list of thumbnails instead of full images? Thanks in advance.

  158. Carlos R Says:

    In addition to the previous, what should I do to link the gallery thumbnails to the images?

  159. chris Says:

    Paul, great plugin. I’m using it in xmlrpc to pass data into Flash for cms purposes.

    One question : I’m confused as to why this method does not pass back a param that is tag name? This seems like an essential piece. Is there another way to get this?

  160. Brandon Says:

    Hi Paul,

    I’m attempting to create an intranet site and wanted to have a page of PDF links using your plugin so users could just tag their media uploads and have them appear on the proper page. I’m attempting to use the shortcode to inject the PDF’s into the page; but all I see are the appropriate number of bullets with no link to the PDF. I’m using WP 2.9.2, is there some example code somewhere? Shouldn’t [media-tags media_tags="downloads"] just display all the PDF’s with the ‘downloads’ tag or is it necessary to modify one of the template files to use the shortcode?

  161. Tom Says:

    Around line 83 of media_tags.php looks like this:

    if ((isset($_REQUEST['activate'])) || ($_REQUEST['activate'] == true))
    {
    $this->mediatags_activate_plugin();
    }

    This does not look like it is logically correct (and kicks up a warning ‘Undefined index: activate’). Should a logical AND ?

  162. Ross Beyeler Says:

    I built a custom function that would query the database for all existing mediatags and list attachments for each mediatag underneath. It also filters out the attachments to only display those that were uploaded by the currently logged in user. This is something we needed to build for a client looking to setup a file management type system. The code isn’t pretty and displays all mediatags whether the currently logged in user has attachments in them or not:

    function list_attachments_by_user_tags() {
    global $wpdb, $current_user;
    $user_id = $current_user->ID;
    $catQuery = $wpdb->get_results(”
    SELECT *
    FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id )
    WHERE wtaxonomy.taxonomy = ‘media-tags’
    AND wtaxonomy.parent = 0
    AND wtaxonomy.count > 0″);
    foreach ($catQuery as $category) {
    echo ” . $category->name . ”;
    $media_items = get_attachments_by_media_tags(‘media_tags=’.$category->slug);
    if ($media_items) {
    echo ”;
    foreach ($media_items as $media_item) {
    if ($media_item->post_author == $user_id) {
    echo ”;
    echo ‘ID) . ‘”>’ . $media_item->post_title .’‘;
    echo ”;
    }
    }
    echo ”;
    }
    }
    }

    I’d love to hear some feedback.

  163. Ross Beyeler Says:

    My last comment removed all the html from my function, so it probably looks broken. Hopefully this works:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    function list_attachments_by_user_tags() {
        global $wpdb, $current_user;
        $user_id = $current_user->ID;
        $catQuery = $wpdb->get_results("
            SELECT *
            FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id )
            WHERE wtaxonomy.taxonomy = 'media-tags'
            AND wtaxonomy.parent = 0
            AND wtaxonomy.count > 0");
        foreach ($catQuery as $category) {
            echo '<li><h3>' . $category->name . '</h3>';
                $media_items = get_attachments_by_media_tags('media_tags='.$category->slug);
                if ($media_items) {
                    echo '<ul>';
                    foreach ($media_items as $media_item) {
                        if ($media_item->post_author == $user_id) {
                            echo '<li>';
                                    echo '<a href="' . wp_get_attachment_url($media_item->ID) . '">' . $media_item->post_title .'</a>';
                            echo '</li>';
                            }
                        }
                    echo '</ul>';
                    }
        }
    }
  164. noponies Says:

    Hi Paul,

    Is there anyway to exclude a particular media tag from the list returned by get_attachments_by_media_tags. I’ve tried the usual wordpress ‘exclude’ and ‘tag__not_in’ etc, but come up short. I can get around is using array methods on the returned list, but a simple exclude command would be handy.

  165. prostonik_5 Says:

    Three suicide attacks in the central Iraqi city of Baquba kill at least 31 people, days ahead of parliamentary elections.

  166. Pachi Says:

    Hi paul, I was wondering if I can use 2 calls of get_attachments_by_media_tags in a same page, because i’m trying to do this, but on second call.. always return empty result..

    I take a look to your code and found the problem, but i cant fixit… on second call, media_tags.php file, at this line:

    $attachment_posts = get_posts($query_str);

    get_posts return nothing…. the strange thing is that on my localhost (LAMP) works fine, but on hostgator fails.. any help?

  167. Paul Menard Says:

    @Pachi: Thanks for the comment. Having multiple calls to MEdia Tags (assuming you are using shortcode) should work just fine. Can you provide the exact call parameters you are using for both? I would like to review and test on my dev system. Thanks.

  168. Mike Schinkel Says:

    I’m working with a beta of wp3.0 and tried installing MediaTags and it crashed. Seems that $wp_rewrite is null when you attempt to register taxonomy on line 67 of media_tags.php which is in the MediaTags class instance constructor. The error message started with:

    Fatal error: Call to a member function add_rewrite_tag() on a non-object in /Users/myname/Sites/mysite/wp-includes/taxonomy.php on line 268

    I found that by initializing the MediaTags class instance it in an ‘init’ hook rather than simply at the bottom media_tags.php seems to have solved the problem (though I haven’t fully tested it yet.)

    So instead of what is on line 410 of media_tags.php:

    $mediatags = new MediaTags();
    ?>

    Use this:

    add_action(‘init’,'init_media_tags’);
    function init_media_tags() {
    $mediatags = new MediaTags();
    }
    ?>

    HTH.

    -Mike

  169. Mike Schinkel Says:

    Oops, I think I spoke too soon. Maybe it should look more like this (note the “global” declaration):

    add_action(‘init’,’init_media_tags’);
    function init_media_tags() {
    global $mediatags;
    $mediatags = new MediaTags();
    }
    ?>

  170. Paul Menard Says:

    @Mike Schinkel: Thanks for the notes on this. I’ve not had a chance to do a 3.0 review. Will apply these changes you suggested.

  171. chodorowicz Says:

    just wanted to thank you for making this extremly helpful plugin – I was for a way to let use images in custom places in my templates but in a more user-friendly way thank coping urls to custom fields – this plugins works perfectly for this task

  172. Keith from shrewdies Says:

    Paul, I cannot thank you enough for this plugin. I have a lot of PDFs on one of my sites, and media-Tags makes the organization easier, and the presentation better.

    One slight frustration I had was the necessity to edit tables directly to make proper use of sorting by menu_order – I cannot find an edit screen in WordPress that allows me to change this for anything but Pages.

    Anyway, I hacked your code in mediatags_admin.php and added the following to the beginning of mediatags_show_fields_to_edit

    $form_fields['menu-order'] = array(
    ‘label’ => __(‘Menu order:’),
    ‘input’ => ‘html’,
    ‘html’ => “ID][menu_order]‘
    id=’attachments[$post->ID][menu_order]‘
    size=’10′ value=$post->menu_order />”
    );

    It works brilliantly – I can now order my lists easily at the same time as adding the media tags. Thanks again – I’ll go and give you the 5 stars in WordPress.org you so richly deserve.

  173. Paul Menard Says:

    @Keith from shrewdies: Thanks for the comment. And thanks for the code addition. I’ll review and consider adding in the in the soon to be released next version. And thanks for the 5 stars. Much appreciated.

  174. Mike Schinkel Says:

    @Paul: Thanks for the reply.

    Another note on Media Tags, I’m following Andrew Nacin’s recommendation[1] to use WP_DEBUG and I’m getting lots of undeclared variable errors (which are easy to fix, but if I fixed, you revise and then I upgrade, my fixes are gone.) I’m wondering if when you do your 3.0 review you can do it with WP_DEBUG turned on?

    Thanks in advance.

    [1] http://www.andrewnacin.com/2010/03/22/deprecated-functions-and-wp_debug/

  175. Johnny Peck Says:

    Aloha Paul, I just wanted to thank you for your hard work on Media Tags. I’ve just created a short-code plugin that uses your plugin to get images into a gallery. Tag Gallery is just like the gallery short-code already included with WordPress but uses tags from your plugin to get the images. Your tags and my plugin make it much easier to manage galleries rather than the currently awkward way it is done. Anyhow, thanks again and if your interested, check out the plugin on WordPress at the following url http://wordpress.org/extend/plugins/tag-gallery/

    Once again, thanks and aloha.

  176. Paul Menard Says:

    @Johnny Peck: Thanks for the reply. I just checked out your plugin. This is freakin awesome! Thanks man. One note or request. In the description page can you add a link to the Media Tags plugin in the line “REQUIREMENTS: You must have Paul Menard’s Media Tags plugin installed or it will do nothing for you.” would make it easier for people to download. Thank again.

  177. Johnny Peck Says:

    Paul, I just updated the description with a link. It should update to the plugin’s site next time they update. I guess 15 minutes or so. I’m glad you like it!

  178. kirpich Says:

    ??? ??????????, ?? ?????? ????.

  179. Bev Says:

    Hi Paul, I used your plugin on a charity website that needed a list of newsletters in the sidebar. So I create a widget to handle this. I decided to release the plugin so it is available to others until you have a chance to implement widgets on your plugin. The plugin is named “Media Widget”.

    Thanks for your plugin – it is very useful.

  180. Paul Menard Says:

    @Bev: This is awesome. Thank you so much for sharing this great work. You and others have really taken the time to put together some great tool using my Media Tags plugin as a base. Thank You. Thank You. thank You. I’ve just not had the time to work on a widget. No I see there is really no need. One note if I could make a suggestion. In your plugin description “…list media tagged using the Media-Tags plugin by Paul Menard.” Would it be possible for you to link to the Media Tags plugin page http://wordpress.org/extend/plugins/media-tags/. There are a few copy cats out there doing similar Media tagging projects and would not want someone downloading your plugin to use the wrong media tagging plugin. Thanks again and thanks for sharing.

  181. Bev Says:

    Hi Paul, I added the link.

    My plugin also checks for the presence of yours and shows an error message with a link if it is missing.

    Cheers!

  182. Medotit Says:

    ??????????? ??? ???????, ???????.

  183. Spencer Ludban Says:

    Great plugin! This has saved me lots of time. One minor thing: different sources document the name of the archive template file differently. The body of this post says it’s mediatags.php, as does the readme.txt included with the plugin, but the writeup on the WordPress Plugins Directory and your comments here indicate that it’s mediatag.php. I did figure out that it’s the latter, but it took a bit of messing around to discover that this was my issue. Thanks again for your work on this!

  184. Diana Says:

    I have an issue with the plugin: Media tags appear in my post-tagcloud. I’ve now created four media tags, and two of them are also in my posts tag cloud, two of them are not. All tags have associated media.

    Is this a known issue?

  185. Paul Menard Says:

    @Diana: This is strange and for the record not a known issue. The Media Tags are stored in their own Taxonomy in WordPress. So to say they are showing up in your post tag cloud seems strange. Is there a page I can see this on? Also what version of WordPress? What other plugins are you running?

  186. Diana Says:

    Hello Paul,
    i figured out what the problem was, but not how it was caused: Two of the media tags were copied to the post tags, for some reason. I’ve already cleaned it up. I’m running the latest version of WordPress with the following plugins:
    - Admin Notes
    - Autotagger
    - Media Tags
    - Tag Gallery (not used in any posts yet)

    I feel that Autotagger may have something to do with it, the two media tags that were copied did have a post tag as substring. I’ve tried to reproduce the error, but couldn’t. If I find a way to reproduce it, I’ll let you know.

  187. bas_der_gruene Says:

    I have a problem use your plugin on my site but some essentially things do not work.
    When i am trying to use the permalinks and go to the address something/media-tags/sometag I only get a 404 back. Every time. Second thing is: Shortcodes doesn`t work either.
    I managed to hardcode php-code into template-files, and got some tagged files back, but I would appreciate to use the template without hardcoding (especially because I am just the admin, not the user adding those tags)

    My site is only for registered users accessible and for this reason it is heavily using plugins, but as far as I can tell by looking into your code (or hooks), those aren’t interfering. (I also gave it a try with all critical 3rd-party plugins disabled, but doesn`t work).

    Any similiar errors known? Maybe something with my server configuration?

    Beste regards, bas_der_gruene

  188. Paul Menard Says:

    @bas_der_gruene: Well how about some information regarding your setup. Since you provided an example of the media-tag URL. I’m assuming you have Permalinks enabled. Can you provided what version of WordPress you are running? What other plugins you are running? Etc. Also, since the shortcode is not working can you ensure the Media Tags plugin is actually enabled. Thanks. Let me know. Best.

  189. bas_der_gruene Says:

    Media Tags plugin works almost fine. I can use those template-functions, my Media is already tagged. I do run the newest wordspress version 2.9.2
    Those Plugins are running (and may be important) on my site: Advanced Category Excluder, Event Calendar, Recent Comments Widget, Brien`s Threaded Comments, Role Manager, User Access Manager (+some smaller, some own ones)

    I think I have to find this bug myself, especially because I first have to do a research which changes I made to my theme over the last two years. Some of them aren`t standard procedure, I think…

    Just wanted to know wether there are any similar bugs known.

    Hav a nice Day, and thanks for the plugin, bas_der_gruene

  190. MadtownLems Says:

    Great plugin – much needed functionality!
    However, I can’t seem to find a way to, from the Admin end, easily filter by Tags. Yes, if I click on a tag in the Media Tags column, it filters by that, but this requires me to first find a media piece with the tag I want to filter by – which kind of defeats the purpose.

    What about a list of all Media Tag Cloud available on that page to assist in filtering? (maybe hidden until someone clicks ‘Show tags’?)
    thanks again for the plugin!

    – jason

  191. MadtownLems Says:

    RE: my last post
    Ok, found I can click Media Tags, then click the # in the Used Column to filter by that! Yay!

    – jason

  192. MadtownLems Says:

    Hi – having some trouble with the /media-tags/slug view, in that it keeps saying nothing matched my post.

    I’ve double checked the permalink structure, but like I said, I get “No posts matched your criteria” rather than a 404.

    I know that I have media tagged with those things.

    I get the same thing when I click on the View link from the Media Tags when a tag eveb says it has 2 things.

    Can you confirm this page works in a MultiUser environment? I don’t see why this one part of it wouldn’t. I’m running 2.9.1.

    Also, is it possible to use TWO slugs like this? Such as:
    /media-tags/foo/bar or foo+bar?

    Please let me know if you have any suggestions!
    Thanks!!

  193. Paul Menard Says:

    @MadtownLems: I can confirm the Media Tags plugin should work on WPMU. Though I’ve not tested on 2.9.1. More like 2.7.1. Some version from last summer. Do you have a public URL for me to investigate the issue?

    And no the plugin was not developed with the ability to concat tags together. This may be coming in a future release.

  194. Paul Menard Says:

    @James Braithwaite: James, My apologies. This is an actual bug in the code. Seems some code I lifted from another plugin way back in 1.0 has some hard-coded table prefixes. If you want to make the edit open the file mediatag_rewrite.php. In this file is a function ‘mediatags_postsWhere’. Within that function there are 7 instances where ‘wp_posts’ was used. These need to be replaced with ‘$wpdb->posts’. I have this fixed and working on some other changes before submitting the plugin to the wordpress.org repository.

  195. spacechampion Says:

    This is a great plugin… would it be much trouble to extend it to Links as well? Ideally, a tag page would call up all posts, pages, media files and links that have that tag slug.

    It seems like the WP core development team for 3.0.x (sometime this year) wants media and users to have both categories and tags (I hope they are considering links too), so that everything can be tagged or categorized.

    You should get your work into the core. :-)

    If you don’t want to work on Link tags, I wouldn’t mind trying my hand at modifying your code to do it.

  196. Paul Menard Says:

    @spacechampion: That is an interesting concept on the Link tagging. I would not modify the Media Tags plugin. Instead maybe clone some of the code and use it as a new plugin. And yeah I read about WP core team identifying features like Media tagging to be included in core. The have done this to me before. Two years ago I wrote a Revisions plugin to handle Post and Page versioning and restore. Six months after they included versioning in WP core. I do know that have looked at my Media Tags code for considerations. Which does make me somewhat happy.

    Back to the Link Tagging I don’t think it will take much. Thanks for the idea. I’ll start on that soon.

  197. hellofold Says:

    hi. i seem to be having some issues with getting good ol 404s when i click on a media tag link. i’ve successfully assigned tags and gotten them to show up in the sidebar widget, but when i click the link, it doesn’t find anything. at first i thought this might be because i was linking to images that only existed inside a gallery, but then i tried it for an individual post with only one (tagged) image placed in it–still no luck.

    i’m running an independently hosted wordpress 2.9.2 blog with the following plugins: akismet, google xml sitemaps, lightbox 2, media tags, seemore, sliding read more, and tag list widget. any opinions? thanks!

  198. Bev Says:

    Hi again Paul, Just a heads up about another plugin of mine that makes use of your Media Tags. WP-Imageflow2 will generate a CoverFlow style image gallery of tagged images.

  199. Bruce Says:

    @Paul: Thanks for the reply.

    Another note on Media Tags, I’m following Andrew Nacin’s recommendation[1] to use WP_DEBUG and I’m getting lots of undeclared variable errors (which are easy to fix, but if I fixed, you revise and then I upgrade, my fixes are gone.) I’m wondering if when you do your 3.0 review you can do it with WP_DEBUG turned on?

    Thanks in advance.

    [1] http://www.andrewnacin.com/2010/03/22/deprecated-functions-and-wp_debug/

  200. Enrico Says:

    Hi Paul,
    as @bas_der_gruene I can’t use permalinks to show archived media llink mysite.com/media-tags/sometag I get a 404 error page.
    Any news?
    Thanks in advance.

  201. Finster Says:

    I’m having the same issue with 404′s on the media tag archives. No amount of setting up templates seems to alleviate. As near as I can tell something is broken with wp-rewrite, though I’m not sure what.

  202. Paul Menard Says:

    @Finster:

    I’ve finally had a chance to research this. I made some dumb changes to the init of the plugin based on some suggestions from others. It is this init hook where the rewrite logic is setup for the media-tags templates. I’ve just updated the plugin version 2.2.8 into the wordpress.org repository. Should fixe the issues. Apologies to all effected by this.

  203. Enrico Says:

    Perfect! It works like a charm? :)
    Is there a way to know in which tag we are, when visiting a particular archive page?
    I’m just trying to build a “by tags”-navigation menù, but no way (for now) to highlight selected tag when I am in archive template.
    I like to have a solution like “current-item” css-class in WordPress navigation links.
    Any idea?
    Thanks for your work!

  204. noname Says:

    not working with latest 3.0 RC:
    Fatal error: Call to a member function add_rewrite_tag() on a non-object in /var/www/vhosts/seo-konzultant.cz/httpdocs/wp-includes/taxonomy.php on line 282

  205. Paul Menard Says:

    @noname:

    I’m still waiting on the WP 3.0 Beta series to finalize development before submitted another patch for the Media-Tags plugin. In order to get this working edit the main plugin file ‘media_tags.php’ Look about line 67. You should see ‘$this->register_taxonomy();’. Move this complete command into the function init(); at line 79. The complete function init(); should look like this:

    function init() {
    $this->register_taxonomy();

    mediatags_init_rewrite();

    // Checks ths plugin version again the legacy data
    if ((isset($_REQUEST['activate'])) && ($_REQUEST['activate'] == true))
    {
    $this->mediatags_activate_plugin();
    }
    }

  206. does Says:

    Fatal error: Call to a member function add_rewrite_tag() on a non-object in /home1/dotnatur/public_html/blogtremblant/wp-includes/taxonomy.php on line 275

    with latest wordpress

  207. Paul Menard Says:

    @does: See this comment

    http://www.codehooligans.com/projects/wordpress/media-tags/comment-page-1/#comment-53028

  208. MadtownLems Says:

    hey hey! I found something weird with export/import of media tags.
    wp 2.9.1 and media tags 2.2.7.

    My Common media tags show up like this:
    s:251:”a:1:{i:0;O:8:”stdClass”:9:{s:7:”term_id”;s:2:”21″;s:4:”name”;s:2:”4h”;s:4:”slug”;s:2:”4h”;s:10:”term_group”;s:1:”0″;s:16:”term_taxonomy_id”;s:1:”7″;s:8:”taxonomy”;s:10:”media-tags”;s:11:”descri

    while my Uncommon media tags look perfect!

    weird, eh? :D

    thanks again for the plugin

  209. Paul Menard Says:

    @MadtownLems:

    Ha. You are probably the only person to have used the export/import. Any chance I can get a copy of the export file? Would like to test with some real export data.

  210. Ben Huson Says:

    Using version 2.2.9.1 with WordPress 2.9.2 if I reorder the images in the gallery either by dragging or changing the order numbers, the order doesn’t seem to save when I save changes. When I disable the plugin this works fine. Any ideas?

  211. Dwayne Says:

    I really like the plugin, and wonder if there’s a way to customise the shortcode to display just the links to the media it filters (rather than the images themselves)? I’m not a coder, but I’d really love to use this to filter PDF files into a ‘download list’ (text hyperlinks)

  212. Paul Menard Says:

    @Dwayne: This is totally possible. When using the shortcode the default output format is list items <li></li>. One parameter you need to include in the shortcode is ‘display_item_callback’ and a function you write to handle the display of the link instead of the default image. Below is an example:

    Here is an example shortcode. This may not be a match for your use
    [media-tags media_tags="sometag" display_item_callback="my_display_links"]

    In your theme’s functions.php add the following function. Note the function name ‘my_display_links’ matches the shortcode parameter name. Note with WordPress shortcodes the functions need to return instead of echo the output.

    function my_display_links($item)
    {
    return ‘<li><a href=”‘.get_permalink($item- rel=”nofollow”>ID).’” title=”‘.get_the_title($item->ID).’”>’.get_the_title($item->ID).’</a></li>’;
    }

    Enjoy.

  213. sergio Says:

    Thank you for this nice plugin…
    I used it in a sidebar widget and noticed a strange behaviour in archive pages.. some media was not selected althoug it was there… I debugged around and my solution was the following:
    around line 351
    replaced
    $query_str = ‘post_type=attachment&numberposts=-1′;
    with
    $query_str = ‘post_type=attachment&numberposts=-1&nopaging=1′;

    This is becouse if the page is a archive page get_posts will use the paging settings from the main loop, unless we pass nopaging=1.
    HTH
    sergio

  214. MadtownLems Says:

    “@MadtownLems:

    Ha. You are probably the only person to have used the export/import. Any chance I can get a copy of the export file? Would like to test with some real export data.”

    sending by email – export/import still wonked.

  215. Paul Menard Says:

    @sergio: Thanks for the comment. Not sure how to answer this but you may be correct. I’ve added the ‘nopaging’ parameter to the defaults but without a value. This means when you call get_attachments_by_media_tags() you can now pass in the ‘nopaging=1′ parameter which will get passed to this get_posts function. Look for this in an upcoming release of Media-Tags. And thanks for add the comment. and for using the plugin.

  216. Neil Says:

    Hey awesome plug-in. I’m using MT version 2.2.8 with WP 3.0 – if I reorder the images in the gallery either by dragging or changing the order numbers, the order doesn’t save when I save changes. If i show image fields and edit the ‘menu order’ field however, the order is saved. When I disable the plugin the drag and drop ordering works fine. Similar to @Ben Huson above. Do you have any idea what is going wrong here? Thanks in advance for any help. Neil

  217. Paul Menard Says:

    @Neil: Thanks for the replay. This bug was identified and corrected in a new version. You might want to upgrade to the latest version of Media-Tags which is 2.2.9.2.

  218. Neil Says:

    Ahh! It’s on the list.. Thanks again Paul.

  219. Lindsay Says:

    Hi there
    I have been searching for something like this for a while now.. THANK YOU for taking the time to develop it.

    I have a question though.. I haven’t delved into the code yet, but I do have a few questions before I jump in and spend too much time with this..

    Currently I am using the twentyTen theme. This is my first time working with this theme, but I understand that it works with thumbnails a little differently.

    I currently have the ability to pull the first image of a post via category from wordpress and place it in my shopping cart’s pages.

    What I would LOVE to be able to do is tag pictures as I upload them and then have them placed in the product pages based on their tags..

    So if i have pictures of people wearing red shirts on my blog, I tag them with “red shirts”

    then on my cart I pull them out by saying “show all images with the red shirt tag”

    I’m not asking you specifically to write this for me, but more just can your plugin cover this type of application??

  220. Paul Menard Says:

    @Lindsay: Thanks for the kind comment. Much appreciated. I can give you the answers ‘Yes’ and ‘No’

    Yes: The Media-Tags plugin was designed with a number of template functions where you can request image tagged with ‘red shirt’ or whatever. You find this functionality in the template function ‘get_attachments_by_media_tags()’. This function takes a number of arguments. For your purpose you would do something like the following:

    get_attachments_by_media_tags(‘media_tags=red-shirt&post_parent=123′);

    The ‘media-tags’ argument is the slug of the tag not the tag name. The ‘post-parent’ is optional. If not provided will return all images with the specific ‘media-tag’ What is returned from this function is a PHP array of items. Not knowing what shopping cart you are using I cannot advise on how to process the PHP array.

  221. Lindsay Says:

    WOW, thanks so much for your quick reply!! All too many times I end up on plugin pages where the owner hasn’t posted in months. Great job.

    So the cart I am using is oscommerce.. I have managed to work with the thumbnail attachment on the home page of my osc install by using the theme “no” tag on the osc page but requiring the wp-load.. That allowed me to retrieve the get_posts and the bdw_get_images() .. Then I had the array like this:

    // Get images for this post

    $arrImages =& get_children(‘post_type=attachment&post_mime_type=image&post_parent=’ . $iPostID );

    // If images exist for this page

    if($arrImages) {

    // Get array keys representing attached image numbers

    $arrKeys = array_keys($arrImages);

    $iNum = $arrKeys[0];

    $sThumbUrl = wp_get_attachment_thumb_url($iNum);

    $sImgString = ‘‘ .

    ” .

    ‘;

    // Print the image

    echo $sImgString;

    }

    }

    ?>

    So I INTEND on doing something similarly with yours via the get_attachments_by_media_tags

    I am fairly new at php and better at hacking things that people have already done than writing my own.. which is why i came here for guidance.

  222. Paul Menard Says:

    @Lindsay: Thanks. I do try and keep up on user comment as much as possible. They generally have immediate needs.

    From your code sample you can replace the call to get_children with the get_attachments_by_media_tags(‘media_tags=red-shirt&post_parent=123?); The returned array will be the same. Actually the Media-Tags plugin calls get_children internally after filtering by the tag slug. Good luck!

  223. Lindsay Says:

    Awesome Paul.. and THANK YOU!!

    I will update you with how it goes. It seems there is a big movement over at the osc site to combine osc and wordpress.. If I can some how manage to create a form in osc which creates a new column in the product info table, then I will have the website admin create a product and put in the media tag that goes with that..

    Then when the person views the product page, osc will automatically pull the content based on the tag associated with that product..

    OYE, that sounds like a load of work.. Hah.. wish me luck!

  224. Lindsay Says:

    Hmm.. I have been playing with this.. I am not ENTIRELY sure what is going wrong, but here is my code:

    ID;

    // Get images for this post

    $arrImages =& get_children(‘media_tags=bibst&post_type=attachment&post_mime_type=image&post_parent=’ . $iPostID );

    // If images exist for this page

    if($arrImages) {

    // Get array keys representing attached image numbers

    $arrKeys = array_keys($arrImages);

    $iNum = $arrKeys[0];

    $sThumbUrl = wp_get_attachment_thumb_url($iNum);

    $sImgString = ‘‘ .

    ” .

    ‘;

    // Print the image

    echo $sImgString;

    }

    }

    ?>

    I can definitely call for images, but when I add the media type, it does not seem to filter.. I also was having issues earlier because I copied and pasted my old code and forgot that the other code was only querying a particular category where with this I want it to pull from ALL posts but only pull from ones with the tag “bibs”

  225. Paul Menard Says:

    @Lindsay: Again you should not be using the get_children WordPress function. I noticed you are adding the ‘media_tags=bibs’ parameters. This will not work. You need to call the Media-Tags template function like this:

    $arrImages = get_attachments_by_media_tags(get_children(‘media_tags=bibst&post_type=attachment&post_mime_type=image&post_parent=’ . $iPostID );

    Then see if the rest of the code you wrote works out. Also, to not clutter the commented please email me via the contact form. I’d like to take this PHP help offline. Thanks.

  226. Lindsay Says:

    Thanks Paul… I attempted your fix but it did not quite work.. i will email you the details.

    I do appreciate the help

  227. Shon Says:

    Hi there-

    I’m a PHP/Wordpress newbie, so I apologize if this seems ignorant.

    What I want to do is return two properties of images by tag. I would like the image url and the image caption to be returned.

    How would I do this? If I use
    $media_items = get_attachments_by_media_tags(‘media_tags=home’)
    it returns an array with object in it (the ojbects that I need).

    How would I access them?

  228. Paul Menard Says:

    @Shon:

    Yeah this is simple PHP/WP coding. When you call get_attachments_by_media_tags(); what is returned will be an array of images. This is very similar to the posts array when you call the WP function get_posts(). To display the images you will need to code a PHP loop to process each image item.

    Getting the image URL is not a clear question. As you should be aware WP supports different size images for each image you actually upload. So there is not one specific image URL but instead possibly 4 different ones.

    Here is some quick code to get you started.

    $media_items = get_attachments_by_media_tags(‘media_tags=home’);
    if ($media_items)
    {
    foreach($media_items as $media_item)
    {
    //echo “DEBUG: media_item

    "; print_r($media_item); echo "

    “;
    $image_src = wp_get_attachment_image_src($media_item->ID, ‘medium’);
    // image_src[0] == image url;
    // image_src[0] == image width;
    // image_src[0] == image height;

    // From here you will proceed to build the image HTML element and add the caption.
    }
    }

    See the WP Codex:
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

  229. John Philip Says:

    Hi Paul

    Thank you for this plugin. Looks promising.

    How would I use the conditional testing? I’m trying to place it in a function in my functions.php file, but isn’t working.

    This is the what I have tried.

    if (is_mediatag(‘my-choice’)){
    echo ‘My Choice’;
    }

  230. Rene Says:

    First of all: thanx for the writing an supporting of this plugin.
    I found a bug in this latest release and a way to fix it: when using an older (2.9.x) installation of WordPress, I got an error in the mediatags_rewrite.php: undefined function term_exists().
    In line 84 and 154 this function is called and gave an error, but also in the function mediatags_position around line 185. In that last function, there is a check for WP 3.0 or else the fucntion is_term() is called.
    I copied the check for the WP version to the other places where term_exists() is called and everything worked again.

    Just to let you know for a next version or anyone with the same problem, keep up the good work.

  231. Paul Menard Says:

    @Rene: Thanks. Yes, I’m aware of that bug. For some reason the folks who make the decision about the core function changed on the WP 3.0 release. I changed the plugin but didn’t notice they didn’t make the core change backwards compatible. This is handled better in the upcoming Media-Tags 3.0 release.

  232. Neue Version der Heraldiksoftware | Wiesels Luxemburger Heraldik Says:

    [...] ausgelagert, und für die heraldischen Begriffe benutze ich inzwischen in erster Linie die Mediatags vom Code Hooligan aus Austin Texas. Voriges Wochenende habe ich meine eigene Lösung mit den costum [...]

  233. Jeffrey Nichols Says:

    If you’re trying to setup a search form for media tags use this code:

    tag:

  234. Brian Says:

    So I’m lookin’ to call $media_items = get_attachments_by_media_tags(…
    Feeding it variables constructed from a form $_POST. I was thinking the code below should be in a seperate .php file, but I can’t get around the Call to undefined function get_attachments_by_media_tags()

    function displayPhotos($photoTags, $photoCondit, $photoView) {
    $media_items = get_attachments_by_media_tags(“‘media_tags=”.$photoTags.”&display_item_callback=”.$photoView.”&tags_compare=”.$photoCondit.”‘”);
    if ($media_items) echo $media_items;
    }

    function make_thumbs($post_item, $size = ‘thumbnail’) {
    $image_src = wp_get_attachment_image_src($post_item->ID, $size);
    return ‘ID.’”>post_title.’” />’;
    }

    $pLen = count($_POST); //length of array
    $numPost = array_values($_POST);
    $tagArray = array_slice($numPost, 0, $pLen-2);
    $photoView = “make_”.$numPost[$pLen-1];
    $photoCondit = $numPost[$pLen-2];
    $photoTags = implode(“,” , $tagArray);
    if(isset($photoTags, $photoCondit, $photoView))
    displayPhotos($photoTags, $photoCondit, $photoView);

  235. Paul Menard Says:

    @Brian:

    First I’m not sure why you would get function not defined when calling ‘get_attachments_by_media_tags’. This function is located in the Media Tags plugin file mediatags_template_functions.php and is automatically included via mediatags.php

    I do see something strange in your code. Though this might be some strange escaping from the comment form. It looks like you are mixing single and double quotes on the parameters to the function. Look at the very beginning of the of the parameters just before you ‘media_tags it looks like you are using a double quote then a single quote. That my friend will return nothing.

    It might be easier to just build an array instead of building the link ampersand parameter list. Like this.

    $media_tags_params = array(
    ‘media_tags’ => $photoTags,
    ‘display_item_callback => $photoView,
    ‘tags_compare => photoCondit
    );
    $media_items = get_attachments_by_media_tags($media_tags_params);

    If you still cannot get the call to ‘get_attachments_by_media_tags’ working. Make sure first the Media-Tags plugin is active. I know this is obvious. But have to ask. You might try calling the object directly. This is basically what the stand alone function you are currently calling does. Like this.

    function displayPhotos($photoTags, $photoCondit, $photoView) {
    global $mediatags;
    $media_items = $mediatags->get_attachments_by_media_tags($media_tags_params);

    }

    I have no comments to make on your $_POST variable processing.

  236. Burt Says:

    There isn’t a corresponding get_the_mediatags() function call, but it’s what I wanted/needed. I added the following to the bottom of the mediatags_template_functions.php file:

    function get_the_mediatags( $id = 0 ) {
    return apply_filters( ‘get_the_mediatags’, get_the_terms( $id, MEDIA_TAGS_TAXONOMY ) );
    }

  237. Paul Menard Says:

    @Burt: Great. Thanks for sharing your code. I’ll review and see about getting this added to the upcoming Media-Tags 3.0 release.

  238. Brian Says:

    I got it all figured out. It was just noob php problem. I needed to call wp-load before calling all the functions. Thanks for the reply, this is the best feature add I’ve found.

Leave a Reply