Skip to content

Instantly share code, notes, and snippets.

@mytory
Forked from hasinhayder/fetch-attachment.js
Created August 18, 2016 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mytory/283fbaf4996eede9fc765558e5ba4d08 to your computer and use it in GitHub Desktop.
Save mytory/283fbaf4996eede9fc765558e5ba4d08 to your computer and use it in GitHub Desktop.
Fetch WordPress Media Files (Attachments) Via Backbone Model
var attachment_id = 1234;
var attachment = new wp.media.model.Attachment.get(attachment_id);
attachment.fetch({success:function(att){
if (_.contains(['png','jpg','gif','jpeg'],att.get('subtype'))) {
console.log(att.attributes);
$("<img/>").attr("src",att.attributes.sizes.thumbnail.url).appendTo($("body"));
}
}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment