Last active
January 23, 2018 06:00
-
-
Save hasinhayder/eb62a4c02bf4134f5939 to your computer and use it in GitHub Desktop.
Fetch WordPress Media Files (Attachments) Via Backbone Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
What if I need to get attachment by url not id?