Skip to content

Instantly share code, notes, and snippets.

@jordymeow
Created July 26, 2018 06:01
Show Gist options
  • Save jordymeow/22a365165c9757ed0014877c3fb4fbac to your computer and use it in GitHub Desktop.
Save jordymeow/22a365165c9757ed0014877c3fb4fbac 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