Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seancojr/811751fde2cf331941f204c01dbfb48c to your computer and use it in GitHub Desktop.
Save seancojr/811751fde2cf331941f204c01dbfb48c to your computer and use it in GitHub Desktop.
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