WordPress.org

Support

Support » Plugins and Hacks » Extracting EXIF and inserting into taxonomy

Extracting EXIF and inserting into taxonomy

Viewing 3 replies - 1 through 3 (of 3 total)
  • After more searching I imagine this function would suite best: <?php wp_update_attachment_metadata( $post_id, $data ) ?>

    Just need to figure out how to write it up.

    Maybe I can write each attachment location with ID in the $post->ID custom field as an array and extract it later..

    Well I’ve been at it for 24 hours now, and I’m just lost in code. I think the best way to do this is by reading the meta data and using the wp_set_object_terms to write the meta into the taxonomy.

    Let me show you one of the many functions I’ve written up:

    function addTerm($id, $tax = 'location', $term = 'location') {
    	global $post;
    
    	$args = array(
    			'post_type' => 'attachment',
    			'numberposts' => -1,
    			'post_status' => null,
    			'post_parent' => $post->ID
    		);
    
    		$attachments = get_posts($args);
    		if ($attachments) {
    			foreach ( $attachments as $attachment ) {
    				$imgid = $attachment->ID;
    				$imgmeta = wp_get_attachment_metadata( $imgid );
    
    				if ( !empty( $imgmeta ) ) {
    					$latitude = $imgmeta['image_meta']['latitude'];
    					$longitude = $imgmeta['image_meta']['longitude'];
    					$lat_ref = $imgmeta['image_meta']['latitude_ref'];
    					$lng_ref = $imgmeta['image_meta']['longitude_ref'];
    					$lat = geo_single_fracs2dec($latitude);
    					$lng = geo_single_fracs2dec($longitude);
    					if ($lat_ref == 'S') { $neg_lat = '-'; } else { $neg_lat = ''; }
    					if ($lng_ref == 'W') { $neg_lng = '-'; } else { $neg_lng = ''; }
    
    				if ($latitude != 0 && $longitude != 0)
    					$term == $neg_lat . number_format($lat,6) . ', ' . $neg_lng . number_format($lng, 6);
    				}
    			}
    		}
    
        $term_id = term_exists($term);
        $term_id = intval($term_id);
        if (!$term_id) {
            $term_id = wp_insert_term($term, $tax);
            $term_id = $term_id;
            $term_id = intval($term_id);
        }
    
        // get the list of terms already on this object:
        $terms = wp_get_object_terms($id, $tax)
        //$terms[] = $term_id;
        $terms[] = $term;
    
        $result = wp_set_object_terms($id, $terms, $tax, FALSE);
    
        return $result;
    }
    
    //add_action('edit_attachment', 'addTerm');
    add_action('publish_post', 'addTerm');

    Maybe you’ll see what I can’t?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Extracting EXIF and inserting into taxonomy’ is closed to new replies.