Title: Generating attaachment metadata does not work
Last modified: September 28, 2016

---

# Generating attaachment metadata does not work

 *  [xvilo](https://wordpress.org/support/users/xvilo/)
 * (@xvilo)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/attaachment-metadata/)
 * Hi,
 * I have some trouble with images uploaded programmatically to my WordPress site.
   When I am trying to get the attachment metadata, there isn’t any available.
 * So I tried creating my own function, which checks if `wp_get_attachment_metadata`
   is empty and then tries to generate it!
 * Unfortunately, my code does nothing. It does not give any errors, what should
   I do?
 * My function:
 *     ```
       function get_attachment_meta_data_sem($attch_id) {
       	$meta_data = wp_get_attachment_metadata($attch_id);
       	if($meta_data == ''){
       		$attachment_path = get_attached_file($attch_id);
       		$attach_data = wp_generate_attachment_metadata( $attch_id, $attachment_path);
       		wp_update_attachment_metadata( $attach_id,  $attach_data );
       		return $attach_data;
       	}else{
       		return wp_get_attachment_metadata($attch_id);
       	}
       }
       ```
   
 * But in this example, `$attach_data` stays empty.
 * Thank you in advance!
    -  This topic was modified 9 years, 8 months ago by [xvilo](https://wordpress.org/support/users/xvilo/).
      Reason: Some typo's
    -  This topic was modified 9 years, 8 months ago by [xvilo](https://wordpress.org/support/users/xvilo/).
    -  This topic was modified 9 years, 8 months ago by [xvilo](https://wordpress.org/support/users/xvilo/).
      Reason: Better title

Viewing 1 replies (of 1 total)

 *  Thread Starter [xvilo](https://wordpress.org/support/users/xvilo/)
 * (@xvilo)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/attaachment-metadata/#post-8230002)
 * So I have figured it what was happening. For some reason I needed to include `
   image.php`. It seems a bit off to me, but well, yeah…
 * New function code is:
 *     ```
       function get_attachment_meta_data_sem($attch_id) {
       	$meta_data = wp_get_attachment_metadata($attch_id);
       	if($meta_data == ''){
       		$attachment_path = get_attached_file($attch_id);
       		require_once( ABSPATH . 'wp-admin/includes/image.php' );
       		$attach_data = wp_generate_attachment_metadata( $attch_id, $attachment_path);
       		wp_update_attachment_metadata( $attach_id,  $attach_data );
       		return $attach_data;
       	}else{
       		return wp_get_attachment_metadata($attch_id);
       	}
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Generating attaachment metadata does not work’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [xvilo](https://wordpress.org/support/users/xvilo/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/attaachment-metadata/#post-8230002)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
