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?