Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP/LR Sync: Synchronize a custom meta/field with EXIF/IPTC data
add_action( "wplr_add_media", 'myapp_update_media_meta', 10, 2 );
add_action( "wplr_update_media", 'myapp_update_media_meta', 10, 2 );
function myapp_update_media_meta( $mediaId, $galleryID ) {
global $wplr;
$image = wp_get_attachment_url( $mediaId );
$size = getimagesize($image, $info);
if ( isset( $info['APP13'] ) ) {
$iptc = iptcparse( $info['APP13'] );
if ( isset( $iptc["2#090"][0] ) )
update_post_meta( $mediaId, 'city', $iptc["2#090"][0] );
if ( isset( $iptc["2#101"][0] ) )
update_post_meta( $mediaId, 'country', $iptc["2#101"][0] );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment