[wp-trac] [WordPress Trac] #32117: wp_get_attachment_metadata sizes array file misses path if using year/month organizing

WordPress Trac noreply at wordpress.org
Mon Aug 14 13:12:09 UTC 2017


#32117: wp_get_attachment_metadata sizes array file misses path if using year/month
organizing
--------------------------+------------------------------
 Reporter:  thomask       |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  4.2
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+------------------------------

Comment (by bambattajb):

 This problem is actually a little bit annoying ;) Seems the only native
 function for getting an attachment object by ID is
 `wp_get_attachment_metadata()` but it doesn't actually return include a
 path. I could very much be mistaken and of course the way it is may be on
 purpose.

 I got around the problem by doing the following.

 {{{#!php
 <?php
 $path   = dirname(wp_get_attachment_url($img_id));
 $image  = wp_get_attachment_metadata($img_id, true);
 $image['path'] = $path . '/';
 }}}


 {{{#!php
 <?php
 print_r($image['path'] . $image['sizes'][$size]['file']);
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32117#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list