WordPress ‘Attachments’ Plugin Debut

Posted: November 02, 2009 Comments(118)

Some time ago, I began meddling around with WordPress plugins. I had a specific need that WordPress wasn’t quite up to handling out of the box, and any existing plugins were far too over the top for my taste. I’m probably a bit different than most WordPress users in that I like to get my hands dirty with plugins. I’m not a fan of shortcodes doing all the work; I’d much rather integrate the plugin data directly with my theme using good old PHP.

That said, I had an issue where I need to append any number of images to a Post. Sure, WordPress has its image gallery feature built into the editor, but I wasn’t looking for that. I didn’t want WordPress organizing and generating the content for me. It’s not that WordPress dumps out poor markup, it’s just that I was looking to build things by hand.

A number of hours later, Post Gallery emerged. According to the official WordPress Extend page, Post Gallery has been downloaded over 3,000 times. I continue to get a fair number of support requests for the plugin, and I’m really glad to have written it as it taught me quite a bit.

One of the biggest things it taught me was that it could have been written better. A lot better. So I did it, I took all of the shortcomings I saw with the plugin and completely reworked it from the ground up.

Post Gallery will officially be deprecated in favor of Attachments, a brand spankin’ new plugin that serves (in part) the same purpose.

What’s different about Attachments

As I continued to use Post Gallery on various projects, I began to wonder why the heck I decided to store the media in its own table, tucked away from the WordPress Media Library. That was the first bug under my skin. From there, technical issues with media storage snuck in by way of support emails. Then came the issue of wanting to use an image that was previously uploaded; you had to re-upload it. I was quick to decide that the rewrite would absolutely make direct use of WordPress’ Media Library. Not only does using the WordPress Media Library cut out reinventing the wheel, it allows users to recycle the same upload any number of times.

Another peeve I had with Post Gallery was the sorting I had implemented. Needless to say, you can drag and drop to reorder items in Attachments.

The official plugin home page

As of right now, I’m waiting for the WordPress team to officially add Attachments to the WordPress plugin repository. For the time being, if you’re interested in the plugin, you should first follow me on Twitter (@jchristopher) for updates, and then head over to the plugin home page as that will be home base until approval is granted.

In the meantime, if you’d like to check out a quick screencast overview of Attachments, here goes:

Suggestions more than welcome

Attachments will be my pet project for the next few months, as I’ve got a lot of ideas for handling the browse dialog. I realize that it could quickly become overwhelming with lots of media, so I’m going to begin scoping out some possible solutions. If you’ve got a use for Attachments and have any ideas for improvement, by all means let me know!

Get my newsletter

Receive periodic updates right in the mail!

  • This field is for validation purposes and should be left unchanged.


  1. It looks like you’ve done a great job with this plugin. Well done!

    Will it work well on a WordPress MU installation? Do you have any links that showcase interesting uses of your plugin?

    Keep on rockin.

  2. @Joe Lencioni: Great question! I actually haven’t tested on MU, but I’ve just added it to my high priority list — I’ll be sure to post my findings. My initial thought is that it’ll work fine, but better safe than sorry! No showcase sites quite yet, but a need for something like this comes up with almost every project I work on haha. Great suggestion for a section on the official plugin home page though!

  3. Hey Jonathan,

    This looks really handy – though I do have one comment (based on screen cast) – I think it would be quite handy if you could supply the media type (at least the file extension) in the attachments array.

    For example, your selection there included a bunch of files including music and photos, but without writing some kind of basic file type detection I wouldn’t be able to load any directly into the page. It’d be great to dump an assortment of media like this in on a post with no additional effort so I could handle flash movies differently to photos.

    I know I could do it myself in my own code – just grabbing the file extension using my own script – but just thought I’d suggest it as a possible option for improvement (you did ask!)


  4. @Andy: Great suggestion! I will make that change sooner than later with it being so quick. Let me ask, though: WordPress keeps track of the MIME type for each attachment, would that be more useful than the file extension? Should both be provided? What do you think?

  5. @Jonathan: Difficult, because it’s simplicity vs. complexity isn’t it? It’s probably not a bad idea to rely on internal WP detection if they already collect the MIME – it also allows the greatest flexibility for the user. Ultimately, I don’t have a strong opinion either way though, as long as I have some indication of they type of file I am working with.

    Glad you liked the idea, I’ve just got to find a use for it now!

  6. @Andy: I went ahead and just now committed version 1.0.1 and it should show up within the hour. Along with a small bug fix, the MIME type is now returned when retrieving all Attachments. That way if you’ve got GIFs, JPGs, and PNGs, you only need one conditional. It’s a double edged sword, but like you said, simplicity vs. complexity! Thanks again!

  7. Hey Jonathan.
    I found a problem in the function attachments_get_attachments in file attachments.php.

    If there are no attachment in a post, php throws a warning.
    For fixing that warning please change the function as follows:

    function attachments_get_attachments($post_id=null)
    global $post;

    $post_id = $post->ID;

    $existing_attachments = unserialize(get_post_meta($post_id, ‘_attachments’, true));

    $post_attachments = array();
    if( is_array($existing_attachments) && count($existing_attachments) > 0)
    if( count($existing_attachments) > 1 )
    usort($existing_attachments, “cmp”);
    foreach ($existing_attachments as $attachment)
    array_push($post_attachments, array(
    ‘id’ => $attachment[‘id’],
    ‘mime’ => $attachment[‘mime’],
    ‘title’ => $attachment[‘title’],
    ‘caption’ => $attachment[‘caption’],
    ‘location’ => $attachment[‘location’]

    return $post_attachments;

  8. @Bernhard Zebedin: haha wow thanks for the bug report, and thanks so much for including the fix as well! I’ve just committed version 1.0.3 which includes the fix, you should see it show up soon!

  9. The timing on this couldn’t be better. I have to start a project this week that requires a custom image gallery and I had no idea what I’d use to pull it together. I think this is just the thing.

    Any idea if Attachments will run on a server with PHP 4 installed, or are there PHP-5-only functions in use? I’m forced to host on a bit of a legacy system in this case.

  10. @Scott Nellé: Glad it will (hopefully) help you out! Attachments should run just fine in PHP4, but if you come across any issues, feel free to post here or contact me directly and I’ll be more than happy to make sure it works for you.

  11. Your plugin is exactly what I have been looking for….except for one thing, you have to edit the core files. I’m using Thesis theme which uses the hook system., so I’ll see if there is a way around this…I’ll let you know.

  12. @Victor: Glad it might help you out! I did want to be super clear though; the plugin does not require that you edit core files, but theme files. This plugin is more-so meant for WordPress developers putting together their own themes as opposed to integrating directly with the countless themes already out there. Best of luck!

  13. Hi, this post might be a bit out of place, as it is in regards to WordPress Post Gallery (WPPG). I have been using it for 1 of my projects and am thinking to switch to WordPress Attachment (WPA) if necessary.

    I have encountered some issues with WPPG plugin and also would like to know if the WPA has fixed the issue.

    One problem is that, there are times when I edit a post with image attached to it via WPPG, I noticed the images are not loaded correctly in the Post Image panel. And when I hit update post, the image will then be gone from the post. I will then have to reattach the image.

    It may be due to bad internet connections but my client may still prefer it to be solved. Also, it happens only when I use IE8.

  14. Hi, I’m not sure if this a bug, or just a mistake made by me. But when I try to attach files I get the error “Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wordpress\wp-content\plugins\attachments\attachments.php on line 96” and I’m not really sure what to do about it. Any ideas?

  15. Hi Jonathan,

    Great plugin, exactly what I need! However, so far it does not work for me. I can select the pictures I like to include as an attachment in my post, but after I hit ‘Apply’ I get the following error message above the thumbnail in the attachments box:

    Warning: Invalid argument supplied for foreach() in \wp-content\plugins\attachments\attachments.php on line 96

    Also when I try to save the post it does not remember my choice.

    I test it both locally and on my webserver with same results.

    Hope you can help me fix this bug!

    Andre J.

  16. @Tendouji: Very sorry to hear that Post Gallery has given you trouble. If it’s not too much of an issue I’d definitely suggest migrating to Attachments. In general, it is a much more stable and effective plugin.

    @Levi Gideon @Andre: I’ve just committed version 1.0.4 that should fix that bug, but please let me know if you continue to have problems after updating.

  17. Thanks for getting on the issue so quickly. The error message no longer shows up, but there is still an issue with the attachments not getting saved after I save the post. Thanks.

  18. Hello Jonathan,

    Thanks for the quick fix. It does fix the php error message. However, I get the same result as Levi Gideon with attachments not being saved after the post/page was edited.

    Thanks for your work.

    Andre J.

  19. Hello Jonathan!

    Thank you for your plugin.
    I have installed and activated it.
    After some media items have been attached to post and the latter was saved and published nothing is saved.
    And as far as I can see attachments_get_attachments() return empty array.

    I have tested this plugin on local instance of wordpress running thru virtual host. Maybe this could be the reason thou it seems very strange.

    All files I have uploaded with attachments plugin are successfully saved wp-content/uploads directory but no items is passed to post page

    I’d be very grateful to you if recommend me something that could solve this strange issue


  20. The problem was caused by disabled “short open tag” in php settings of my local server

  21. @Alexander Kovalev: Ah ha! Thank you so much, I shouldn’t have let that slip under my radar but thank you. Version has been committed which replaces shortcode echos with longcode versions.

  22. This is a very, very cool plugin! It does exactly what I need — great work! However, I’ve noticed a big problem, sorry!

    I’m using the Role Scoper plugin to manage a fairly complex permissions system for multiple users. The main users have Contributor permissions — they can only create/edit posts and have to wait for an Admin to publish them. I’ve extended their permissions with the ability to upload files — all good so far.

    Role Scoper won’t show anything in the media library that the Contributor didn’t upload which is perfect. So a Contributor can’t delete or use anything uploaded by another Contributor.

    But your plugin doesn’t respect these permissions — I can still see all the files uploaded by everyone in the media library when I use the Browse feature of the Attachments plugin. Not good.

    I guess it’s a lot of work for you, but do you think it’s possible to add integration with Role Scoper permissions?

  23. Thanks so much for the feedback! I’ve just committed version 1.0.5 which gives you the option to limit the available attachments to those uploaded by the current user. That should help issues with both “Member” and “Role Scoper”. Please let me know if you continue to experience any issue!

  24. Thanks for the great plugin Jonathan!
    I am running in a problem trying to move WordPress+attachments plugin from one host to another.

    The attachment data in the db table wp_postmeta (meta_key: _attachments) contains the absolute path to the attachments and now that i moved the WordPress installation to a new host the attachment URLs still refer to the old host. When i try to search/replace the old hostname with the new hostname all attachment data is lost. It’s still in the db table but it won’t show up in WordPress admin in the post attachment section. Any ideas whats going wrong here? Thanks.

  25. I’m running into a trouble with captions. I have the latest version of WP running. When I add attachments, everything works fine. But as soon as I add a caption to any of the images and then update the post, all of the attachments are removed from the post. They’re still attached via the core WordPress system – so I can still add images via the Browse area – but aren’t listed in the Attachments system anymore.

  26. @Dan Philibin: Very sorry to hear that! Can I have a bit more info from you so I can troubleshoot the issue? First, have you tried deactivating all other plugins and making sure there’s no interference on that level? If so and the problem still occurs, which browser(s) have you tried it in? Thanks in advance.

  27. I have a problem in the administration page of posts (and pages too).
    After activating the plugin I see the new “Attachments” box and I see even the buttons “Browse” and “Add new”. But the browse button does not work.
    I checked the page attachment.php to see if there was a problem with the link of the button and I found this:


    Is it normal that href is =”#”?
    Otherwise, can you help me understand why the browse button does not work?

  28. Sorry, HTML has been purged.
    What I wanted to show was this: [a href = “#” class = “button button-highlighted browse-attachments”] referred to the Browse button.

  29. Yes, that is in fact the proper href. Sometimes (especially if you have lots of media) it takes a moment or two for the browse modal to show up. Did you give it a few seconds and still nothing happened? What other plugins are you running on the site?

  30. I waited several minutes but unfortunately nothing happens. The site is new, just installed, and the only plugin that I’m using are cformsII and Askimet.

  31. I have the same problem.

    Also the plugin does not seem to recognise already added attachments (images) to a post. No items are shown in the list, nor is the ‘Gallery’ tab showing when I click the plugins ‘Add’ button, it is there when I click the regular ‘Upload/insert’ link. Or are items added with the plugin kept separate from the regular media attachments?

  32. Jonathan I love this module, but I’ve run into a problem with the ordering of attachments. I have a post with about 10 attachments. I am trying to swap a bunch of the positions, but one attachment is moved + the revert back to my orginal order when I hit update. Any ideas?

  33. Great plugin. Thanks. Already extending with some front-end funcs – eg. to produce list of attachment links with media-type icons, etc. Do you happen to know if theres a list anywhere of the standard mime-type strings WP uses? (As far as I understand its based on what the server supports/returns, but info seems scarce). Cheers 🙂

  34. Hey… Great plugin!

    I’ve just one little question…
    Would it bee too hard to actually create an entry as an attachment?
    This way It would bee so much easyer to manage the Media Libray as you would automatically see that file “X” was attached to post “Y”.


  35. I just wondered whether your plugin, which seems from the comments to be very good, would be appropriate to be adapted for use in enabling the addition of attachments to comments? Many thanks, Stephen

  36. I’m actually planning on integrating just that but want to stray from involving Attachments into too many WordPress core functionalities. I will definitely add your request to the pool, thank you for leaving the note!

  37. Hi Jonathan,

    You’ve created really great and useful plugin but there is still problem with bug reported in previous comments (comments ids: 15826, 16747, 16759).
    attachments_get_attachments function returns undefined variable when there is nothing attached to post. It should return empty array in this case.
    To fix this you should initialize $post_attachments array before those lines:
    // We can now proceed as normal, all legacy data should now be upgraded
    if( is_array( $existing_attachments ) && count( $existing_attachments ) > 0 )

    I saw in changelog that it was fixed in version 1.0.3 but there is still bug in the code in current version.
    I’m using Attachments and WP 2.9.2

  38. Hi Jonathan,

    Fantastic plugin. Very easy to use.

    One question though, is there a way of getting the thumbnail of the first image (and first image only)?

    Say I have a loop of blog posts, and for each post I want to display a thumbnail of first attached image. (Even better if you could use location, so it just pulls the url to the thumbnail image).


  39. Hi, Jonathan. Great plugin, I was searching for this for a long time.

    But I have a little problem. How can I enable Attachments screen on Custom Type Posts?

    I’m using WP3.0 beta2 with Attachments


  40. @Nathan – Since $attachments is an array, the easiest way to grab the first attached image is to specify the ‘0’ record.


  41. Jonathan, a while back I found Post Gallery and found it very useful. Then you upgraded to Attachments and there was a simultaneous WordPress update which somehow broke Post Gallery for me and I was forced to upgrade immediately (and I lost all my photos uploaded with Post Gallery). I have since recovered many of those images.

    I have another project which still uses Post Gallery on an outdated WP install.

    Is there an easy way to migrate images from Post Gallery to Attachments? I’ve spent some time looking through FAQs and blog posts but haven’t seen anything.

  42. I’m running into problems with posts which have been saved as a draft.

    After publishing a posts which has been saved as a draft for a few days, I’ve noticed my images no longer display on my homepage, but they appear on my post page(single.php). In the “edit post area” area, the preview thumbnail disappeared as well.

    If i were to attach another image to the same post, I’d get a duplicate image in my post page but it the image would appear on my homepage.

    Any ideas why this is happening?

  43. Never mind… i found the issue. My problem was caused by a similar plugin which i forgot to deactivate

  44. Hello,
    I’m looking to have aa generic images appear whenever the attachment area is left blank. How would I do that? I tried adding the following code to the Attachments code;

    <img src="/images/image-blank.jpg” alt=”” />

  45. this is what i meant to display:

    <img src="/images/image-blank.jpg” alt=”” />

  46. Hi Jonathan- awesome plugin! This is how WP should have done media from the get go. This is perfect for a site that has a clean, semantic, custom html/js gallery of photos (photography portfolio).

    However, I noticed there is no filter for assigning attachments dialog? In the normal gallery view, you can filter by month (not all that helpful really) and search.

    I think if I’m able to require prefixes for each image collection, the search could work perfectly to filter out a set of images.

    Could you maybe guide me (high level) on where / how to do that? I’m new at WP, but am a career web dev (asp.net / php) so could probably figure out quick if I had a couple clues…

    Also, do you have this plugin in source control? Github can host for free and then we can fork bug fixes and new features for you! 😀

    Thanks a ton for the plugin!

  47. This plugin is KICK ASS!!!

    Just wondering; how would I pull attachments from another post?

    For example, let’s say I have attachments on a post called “alpha,” and on post “beta,” I want to run the attachment loop, but pull in the attachments from “alpha.”

    I’m sure it’s simple, but I’m not sure how one would do that.

  48. Hey Dave, unfortunately no there is no upgrade plugin. The way the assets were stored was the primary reason for the rewrite and I have not yet written an upgrade script (hence the new plugin entirely) and at this time do not currently have plans to do so. If this is still a long standing problem, how many assets are currently in use on the other site?

  49. Hi Rick — you could include an else portion to the conditional that checks as to whether or not there are any Attachments and if not, dump out your alternate image.

  50. Hi Jason – I currently have a long list of to-do’s regarding filtration and sorting for Attachments. Unfortunately the project has been a bit sluggish due to my getting married last week but with that complete I do plan on spending some newfound free time on the plugin over the next month or two. Please by all means feel free to post any additional feature requests here and I’ll do my best to integrate anything that will make the plugin that much more useful. Thanks for the feedback!

  51. Glad you like the plugin! You can force a return of Attachments from another post by passing the ID of the Post/Page you’d like to use, e.g.

    <?php $attachments = attachments_get_attachments( 123 ); ?>

    where 123 is the Post/Page ID you’re looking to use.

  52. I wouldn’t say that’s unfortunate – congrats on the marriage!

    If it gets to be a bit much work to keep updating it, hosting on public source control (github) can be huge help. Someone can fork (branch) the code for a feature or bug fix, and then submit it to you. Then you can edit it, accept, or disregard any changes – might help get some updates with a bit less work on your side!

    Thanks for the update!

  53. Sorry, one more thing (hate to be a pest).

    Is there an easy way to get attachments from multiple posts?

    Let’s assume I’m suppling the plugin with three ID’s: 2,4,6. Would I be able to use an array or something to extract the attachments from the indicated posts?

    Sorry, I’m a bit of a noob.

  54. @Jonathan Thank you for taking the time to share this excellent plugin with your fellow WordPressers!

    It took me a minute to work out how to pull in thumbnail images so I thought I’d throw up the solution here:

  55. Hi, this is definitely my favouite plugin, so simple and effective compared to vanilla wordpress gallery/attachments manager 🙂

    Just one question, how could i load the medium sized image (or thumbnail) instead of the original?

  56. Hey Great Plugin in fact the must usful plugin in my current proyects.

    I have some headache trying to resolve one puzzle in one of my websites, let me open the first peace :

    I put this code in my funtions.php:

    function the_gallery() {

    $attachments = attachments_get_attachments();
    $total_attachments = count($attachments);

    if( $total_attachments > 0 )
    for ($i=0; $i < $total_attachments; $i++)

    echo '’;



    else {

    I call it from a template file named: gallery.php, that contains a code to make the attachments show in a jquery gallery , more or less this way:

    and all this is placed in single.php

    But what if I want to add a conditional to this

    is this possible???


  57. Hello
    Jonathan ,your plugin is great but i am finding it a bit difficult to make it run in my system,I have installed it in wordpress 2.9 and wordpress 3 but in both the case I am not getting the added file list when I click on browse file.Please help me out as my project got stuck here.

  58. Hello Jonathan
    Thank you for your reply of my mail,its really very kind and nice of you to take time and reply me.
    the plugin is working like a charm in wordpress 3 now.
    thanks once again

  59. with (‘WP_DEBUG’, true) on: I get notice errors: “attachments.php line 341 … error at offset for unserialize()”… replacing unserialize() to with wp’s maybe_unserialize() removes the notices.

    love the plugin <3

  60. **& an “isset()” check:

    ` 341: $legacy_existing_attachments = (isset($existing_attachments[0])) ? maybe_unserialize( $existing_attachments[0] ) : ”; `

  61. Just wanted to say thanks to Jonathan Christopher for the attachments plugin! I’m sort of wondering why non-image attachments just don’t show up with their associated icons when inserting the standard [gallery] in a post/page but the Attachments plugin does the trick!

    Some suggestions:
    i) Pull the title and caption (and description) from that entered in the standard WP Media as the default for the attachments array.

    ii) Also allow re-ordering by putting in an integer field like in the WP standard media gallery functionality. The drag and drop re-ordering is awesome but cumbersome when there are a large number of attachments.

    Here is some code I added to my template to display the attachments with the Media title – note that I parse out the filename but then I decided not to use it. I added this in immediately after the_content(). Thought someone might find this useful.


    0 ) : ?>

    <?php for ($i=0; $i


    $tmp_path_array = explode(“/”,$attachments[$i][‘location’]);
    $tmp_array_length = sizeof($tmp_path_array)-1;
    $tmp_filename = $tmp_path_array[$tmp_array_length];
    <a href="” alt=”” title=”” target=”_blank”>
    echo "$j) $tmp_title“;


    The associated CSS is:
    #attachments {
    margin: 2em;
    .attachments-div {
    position: relative;
    float: left;
    padding: 5px;
    margin: 5px;
    border: 1px solid #000000;
    text-align: center;
    width: 300px;
    height: 160px;

  62. My code didn’t come through properly. Try again

    0 ) : ?>

    <?php for ($i=0; $i


    $tmp_path_array = explode("/",$attachments[$i]['location']);
    $tmp_array_length = sizeof($tmp_path_array)-1;
    $tmp_filename = $tmp_path_array[$tmp_array_length];
    <a href="" alt="" title="" target="_blank">
    echo "$j) $tmp_title";

  63. Hi Jonathan, this plugin is fantastic, and exactly what I needed. However, I’m running into the same issue that others seem to be: when I click the browse button, I get a blank popup, preventing me from using the plugin. I’m running a fresh installation of WordPress 3.0 with Akismet as the only other plugin. Has a solution to this problem been found?

  64. Hi Erica, glad you’re liking Attachments. I have had to troubleshoot that specific issue from time to time but it always came down to using an outdated version of Attachments. Are you using the most recent version (1.1.1 at the time of this writing)?

  65. You, sir, are amazing. I just upgraded my plugin (what?! can’t believe how fast you are) and it works absolutely perfectly.

    Thank you SO much. This rocks. Kudos.

  66. Hey man. Looks like an awesome plugin and I’d love to use it because it would make life so much easier for my clients. However, I only have one button in the attachment field called “post”, I don’t get to “browse” attachments like in your screencast, and I cannot embed videos from youtube for example through the plugin, which makes it unflexible. However, in your screencast all that seems to be possible, is there something I do wrong?



  67. Hi Julian, when Attachments hit 1.5 the two button UI was dropped in favor of a single button that lets you both upload and browse media via WordPress-native modals. Unfortunately I haven’t had a chance to update the screencast quite yet. To attach a piece of media, you can follow the same path of inserting an image into a Post and instead of the button saying “Insert into Post” it will say “Attach” and that will take care of it for you!

  68. I’m building a resource center in WordPress where, thus far, the client has attached resources (MP3s, so far) to a custom post type via the standard WordPress media uploader. They’ve run into a snag and asked if they could just upload them all directly into the Media Library and then attach to individual posts after the fact. I wasn’t finding an obvious way of doing so until I found your plugin.

    The only trouble is, I’m using get_children to return an array of attachments in my theme and, apparently, using your plugin to attach an MP3 hides it from the array. The behavior I was hoping for was to click on “Add Audio” and see the newly “attached” MP3 (via your plugin) showing in the “Library” on the individual post.

    Any thoughts on this dilemma? I’m open to using your function to access the attachments, but would like to stick to using get_children unless I see a compelling reason to do otherwise.

  69. Hey there!
    Nice plugin!

    I’m stuck in trying to show an image thumb with a link to the original size image.
    I find your plugin a perfect solution for my galley need (in combination with http://galleria.aino.se/) but i can’t really figure out how to grab the thumb stored into wp.

    this is the basic string i use

    echo ‘<img src="' . $attachments[$i]['location'] . '"';

    and this is what i need

    echo '‘;

    tried many different solutions (both on template directly and in the attachments.php file – adding a

    echo ‘‘;

    to template and a

    ‘thumb’ => stripslashes( wp_get_attachment_image_src( $data[‘id’], array(80, 60), 1 ) ),

    chunk) but not working so far.
    Any suggestion?

  70. When I originally tested this plugin a few days ago I thought I was too limiting but after some thought I came to the conclusion that it might actually be a better solution than my original plan.

    I need two things though to make this work correctly for me.

    First, when I click the attach button there is no way of quickly finding the files you want to attach and once found, click a checkbox so you can select different images and then press the attach button. I feel we need to have the option to search or filter by file type while also being able to search by name. While the light box window is open one needs to be able to check different files, do a new search, check some more files and then click attach. What I am getting at here is that it should be building an array of attachment/post id’s which then get added to the post metabox after clicking the attach button (which should add all of them at once to the end of any existing files).

    The other thing which I feel is an absolute must have feature is some simple way of adding the post ID for every attachment added through your plugin to a custom field within the attachments post metadata. As I am sure you and others reading this are aware of… The biggest flaw of the default wordpress media library its inability of allowing a media file to be attached to more than one post. This is extremely frustrating for me. If you added this capability then developers could program a media details page so it could show all the posts which has this file attached.

    Could you please either let us know how this can be done or possible update your plugin with these functions? I would greatly appreciate it as well as a few other people I know of who are looking for the same thing.

    GREAT plugin btw!

  71. One other thing… Based on a previous comment made above related to the “capability” addition restricting users from viewing files which they did not upload through their own user account…

    I feel this needs an additional modification. For example, I need the ability of letting specific roles add file where as others can NOT add/modify files BUT they would be able to view the files that are attached. In a different case one role would be able to add files AND delete ONLY those files which he has uploaded but this role would not be able to modify or delete files added by othe users.

    Do these customizations and other capability restrictions already exist in the most recent version of your plugin? If not could this be added and/or could you please provide some examples of how this can be done correctly?

  72. Hey Jonathan,

    Yeah I actually don’t interfere with WordPress’ native implementation of tracking relationships in that way in an effort to not interfere with what WordPress is doing under the hood. Technically the plugin creates the relationship in it’s own way, but they’re a relationship different than what WordPress has built into Core. A number of people have requested that an ‘official’ relationship be made on a WordPress level, but I haven’t made that a default quite yet. Do you think it makes sense to make it an option that the dev can determine whether or not to use?

  73. Hi Martino, you’ll definitely want to use wp_get_attachment_image_src but I haven’t always had luck with passing an array size as per the params and having it work effectively. I could suggest using a third party script such as TimThumb to dynamically generate pixel-perfect thumbnails of your images on the fly.

  74. Attachments used to use it’s own UI which operated much as you described. In fact, you can take a look at the screencast and see one of the first UI revisions that took place. WordPress Extend also makes the older versions of the plugin available which use an alternative browse UI.

    That said, the change was made in an effort to mirror WordPress established workflows as much as possible. I did what I could to ensure that you can Attach multiple files to the same entry without having to close and re-invoke the Thickbox, but WordPress doesn’t provide functionality to select multiple files at once so that could be coming down the line, I’m not positive at this point however. Since version 1.5, this is the first request I’ve received but it’ll definitely be added to the list.

    I don’t quite follow your request about a simple way of adding the post ID for every attachment added through the plugin to a custom field, perhaps you can outline a use case so I can better understand the feature request?

    Attachments should respect which restrictions you’ve placed on the Media library itself. If it’s not, what modifications have you made that are working in the Media library but not in Attachments, and how did you go about implementing the restriction (plugin, by hand, etc)?

  75. Hey Jonathan, i just installed your plugin but i don’t get the browse button at all.
    Using tanzaku theme on wordpress 3.0.1. I deactivated all the other plugins but still no browse button. and i do have a bunch of pictures inside media library .

    Can you give me a hint on how to go about and fix this ?


  76. Jonathan,

    Thanks for the response. I think a dev option would work well. I hadn’t given any thought to the possibility of conflict and, having it a dev level option would bring awareness should a conflict occur.

    Have a great Thanksgiving!

  77. I’m using wordpress 3.0.3 with “User Photo” as the only other plugin besides Attachments.

    With Attachments, I’m perplexed as to how to get the actual images into the post. I followed your example and all of the data about the attachments shows up, but no actual pictures. I noticed that your screencast only shows the data as well, no pictures. Is that all I can get with this plugin?

    Even the URLs aren’t clickable, but if they were, it wouldn’t be enough. I need a set of alternate product views (to use in phPurchase, which I haven’t installed yet), and I thought this would be the way to get them. However, I can’t find any way to show the actual images inside the post they’re attached to.

    For all four attached images, it spits out an ID and mime type, url, caption, everything but an image. If this is actually possible, could you post an example of how to do this?


  78. Any time the browse button doesn’t show up is usually due to another plugin or server config issue. Please try deactivating all other plugins and re-activating them one at a time until the problem replicates itself.

  79. Excellent. That worked great.

    And if I don’t need to specify a size, I can just use the location output as the img src value. And also, if it’s not an image, I get a nice icon with a link to the source (the true value above). Whew!

    Thanks for the help and the quick response!

  80. Obviously I don’t know how to strip code so that it prints here. A simple code tag did not do the trick. 🙁


  81. Is there a way to get the filesize of each attachment? PHP’s built in filesize() will not work with the [‘location’] on my server as not allowed full url..

  82. Hi Jonathan,

    This looks like a handy bit of code, i’ve watched your screencast but im still unsure of the final result. Does the attachments plugin render the selected mediums as actual images/videos you can see in the post? Or does it simply render the mediums pathname to the file..?

    Thanks for your time and efforts

  83. Hi Jonathan,

    Thanks for, what seems to be, an awesome plug-in. I’ve worked with WordPress quite a few times and have used a couple of plug-ins in the past. I’m also an experienced PHP programmer.

    After installing (unzipping and activating) your plug-in, however, I see no difference at all in the “Add post” or “Add page”-sections of the WP-admin. The “Attachments”-box simply won’t show up.

    I feel like a total rookie as no one else seems to have had this problem but from what I can tell the plug-in is installed and activated correctly but simply not showing up.

    I’m using the latest version of WP (3.2) as well as the latest version of your plug-in (

    Here’s a couple of screenshots from the admin:


    Any thoughts?


  84. Be sure to check out the Attachments Settings (found under the main Settings menu) in the WP admin, that’s where you define where Attachments should show up (per post type)

  85. Check out the documentation for the plugin, that’s actually all it returns because it merely facilitates creating the relationship. I’m considering returning image sizes and the like but I was hoping to keep things as lightweight as possible. Since Attachments returns the ID of the media, you can do pretty much anything with that alone using WordPress-native functions.

  86. Thx Jonathan. This is just what i was searching for. Now i have a question. I’m working on a project where some of the posts will need to be included automatically, through API, XML-RPC.

    Do you think that it’s possible to include new posts and configure the attachments like your plugin does, just using the API ?

Leave a Reply

Your email address will not be published. Required fields are marked *