WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 0 down vote accepted

'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'.

share|improve this answer
Awesome - just had a chance to test it and it worked. Thank You! – Andrew Leafe Aug 11 '12 at 3:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.