Skip to content

Instantly share code, notes, and snippets.

@hasinhayder
Last active January 23, 2018 06:00
Show Gist options
  • Save hasinhayder/eb62a4c02bf4134f5939 to your computer and use it in GitHub Desktop.
Save hasinhayder/eb62a4c02bf4134f5939 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"));
}
}});
@jtikon
Copy link

jtikon commented Jan 23, 2018

What if I need to get attachment by url not id?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment