最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

actions - wp_get_attachment_metadata returns false with add_action() 'add_attachment' hook

programmeradmin0浏览0评论

With the following code in functions.php - wp_get_attachment_metadata() returns false and or empty. Perhaps I am attempting to use wp_get_attachment_metadata() before it's ready? As some tests have shown when manually add a previously added $attachement_ID I get the desired information..

function my_custom_attachment($attachment_ID) {

  $meta = wp_get_attachment_metadata($attachment_id); // returns false

}

add_action('add_attachment', 'my_custom_attachment');

With the following code in functions.php - wp_get_attachment_metadata() returns false and or empty. Perhaps I am attempting to use wp_get_attachment_metadata() before it's ready? As some tests have shown when manually add a previously added $attachement_ID I get the desired information..

function my_custom_attachment($attachment_ID) {

  $meta = wp_get_attachment_metadata($attachment_id); // returns false

}

add_action('add_attachment', 'my_custom_attachment');
Share Improve this question asked Aug 10, 2012 at 22:40 Andrew LeafeAndrew Leafe 233 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

add_attachment runs right after an attachment is added to the DB, but but before the metadata is generated. If you don't need the value to be in the database yet, you can use the wp_generate_attachment_metadata filter to hook in. However, if you need the data to be in the database already, you'll have to use updated_post_meta and check that the meta_key passed in equals _wp_attachment_metadata.

发布评论

评论列表(0)

  1. 暂无评论