Media Tags 2.2 plugin for WordPress Released

August 17th, 2009 @ 12pm : 120 comments : Socialize This
Filed Under: Tags: , ,

Over this past week I added quite a few features to the famous Media Tags plugin for WordPress. The list below details many of these new features

  1. Added a new tab to the Media Upload popup box. Anyone familiar with WordPress Post or Page entry is familiar with the popup provided to upload images and other media files. In this popup if you wanted to search for items using the handy Media Tags it was not possible. Now the user is provided with a new Tab labelled ‘Media Tags’. When the tab is clicked the user is presented with a listing of all Media Tags used on the site. Along with the Media Tag name there is a use could in the far right of the listing. This count if greater than zero is a link and will filter the Media Library (another Tab) listing for items from that Media Tags group.

    Below is a screenshot of the new popup tab.

    Media-Tags New Upload popup tab

    Media-Tags New Upload popup tab

  2. More control over the permalink prefix. The Media Tags plugin works with the WordPress Permalink rewrite system to provide ‘pretty’ URLs for the archive. For example if you have some media loaded and tagged on your site for say ‘Texas’. The you can display these items in an archive type listing by using the URL http://www.mysite.com/media-tags/texas/ This format should be familiar to most users of WordPress since Categories and Tags or handled in much the same way. This feature was added in Media Tags version 2.0 and has received much acclaim from the users. The problem is the prefix ‘/media-tags/’ was hard-coded into the plugin. I have a few users request a way to alter this prefix. Other than suggesting they edit the config file for the plugin there was not a good solution.

    So I starting thinking I would just build my own admin page where the user can set this permalink prefix. But I hated having to build a new admin page just for the one setting. Well over the weekend I found the solution of solutions. Why not just add my own field to the WordPress Settings -> Permalink page. This turned out to be quite easy using the new Settings API introduced into WordPress 2.7.

    Below is a screenshot of the new Media Tags Permalink option. The new field just below the standard Category and Tags fields.

    Media-Tag Permalink Slug Prefix

    Media-Tag Permalink Slug Prefix

  3. Playing nice with other plugins. I’ve used the Google Sitemap XML plugin for quite some time and generally install it by default onto any client site I’ve worked on. This is one of those plus plus plugins that can only help your site. Recently I had to figure out a way to include non-WordPress pages into the XML sitemap output. This is actually very easy to do as the plugin authors have provide a nice hook to allow this.

    So my next enhancement to the Media-Tags plugin was to include the Media Tag archives into the Google Sitemaps XML output. This feature is quite powerful since it just adds juice to Google content harvesting. Not wanting to hard-coded this feature into the plugin I ended up building that admin interface I mentioned in the previous point. There is only one option on the page (more to come soon). A simple Yes/No box to include/exclude the Media Tags archive from the Sitemap XML output. I assume most people will wan this but also know there is always the possibility some may now.

    Below is a screenshot of the new Media-Tag admin interface. Look for this under the standard WordPress Settings section.

    Media-Tags Admin Page

    Media-Tags Admin Page

  4. Along with the above mentioned new features I also cleaned up some code related issues. Most of these are under the covers cosmetic items and not related to any screen changes.

Media Tags Future Enhancements

Still on my list of features to add in some upcoming release is Media-Tags Cloud. This is still one of the most requested options for the sidebar. Still working on that code. Trying to follow some of the code written for the built-in WordPress Tags. pretty ugly stuff. Has to be a better way.

Other than the Media Tags Cloud I don’t have any big changes planned for the plugin. Then again the three features mentioned in this post were not planned at all. Just something that hit me on Friday that I started working toward.

So if there is a feature you just think would make the Media-Tags plugin rock for your blog please consider leaving a comment below.

Donations

If you enjoy using the Media Tags plugin or any of my other WordPress plugins, please consider making a donation to show your support. Anything is appreciated. Thanks.

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

120 Responses to “Media Tags 2.2 plugin for WordPress Released”

  1. 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!

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

  3. 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!

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

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

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

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

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

  9. 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!!!

  10. 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!

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

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

  13. 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!

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

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

  16. 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!

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

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

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

  20. Carlos Says:

    Paul,

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

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

  22. 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).

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

  24. 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!

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

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

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

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

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

  30. 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 [...]

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

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

  33. 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!

  34. 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
    }
    ?]

  35. 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…

  36. 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!

  37. 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! :-)

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

  39. 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. :)

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

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

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

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

  44. 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…

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

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

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

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

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

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

  51. 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. ,

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

  53. 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’);

  54. 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/

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

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

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

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

  59. 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?

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

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

  62. 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?

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

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

  65. Emeric Says:

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

    All the best from Paris, Emeric

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

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

  68. 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?

  69. 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/

  70. 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?

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

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

  73. 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!

  74. Paul Menard Says:

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

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

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

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

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

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

  80. 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!

  81. 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)

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

  83. 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;

  84. Emiliano Jordan Says:

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

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

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

  86. 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()

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

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

  89. 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; [...]

  90. 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?

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

  92. 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!

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

  94. Kim Flournoy Says:

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

    -Kim

  95. 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?

  96. Frances Leyland Says:

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

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

  98. Frances Leyland Says:

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

  99. 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?

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

  101. 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!

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

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

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

  105. Eric Di Bari Says:

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

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

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

  108. 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…

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

  110. 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!

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

  112. 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!

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

  114. Carlos R Says:

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

  115. 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?

  116. 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?

  117. 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 ?

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

  119. 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>';
                    }
        }
    }
  120. 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.

Leave a Reply