You can simply adapt this code for your needs:
<?php
// Add an IPTC or EXIF tag to a photo tag or album cat. Code to be inserted into Table VIII-B99: Custom Photo proc
// This example adds IPTC tag 2#080 (photographer) as a tag to the photo and as a category to the album the photo is in
$tag = '2#080'; // Specify the tag
// Get the photos value for the tag. The IPTC/EXIF data must have been saved during upload/import_request_variables
// For exif: use wppa_exif table as opposed to wppa_iptc in the next query
$value = $wpdb->get_var( "SELECT description FROM $wpdb->wppa_iptc WHERE photo = $id AND tag = '$tag'" );
// Process value only when not empty
if ( $value ) {
// Log value found
wppa_log( 'obs', 'Processing iptc/exif tag ' . $tag . ' with value ' . $value . ' for photo ' . $id );
// Sanitize value
$value = str_replace( ',', '', $value ); // commas not allowed
// Get existing tags
$old_tags = wppa_get_photo_item( $id, 'tags' );
$new_tags = wppa_sanitize_tags( $old_tags . ',' . $value ); // formats and removes duplicates
// Save new tags to photo data
wppa_update_photo( array( 'id' => $id, 'tags' => $new_tags ) );
// get the album
$alb = wppa_get_photo_item( $id, 'album' );
// Get existing cats
$old_cats = wppa_get_album_item( $alb, 'cats' );
$new_cats = wppa_sanitize_cats( $old_cats . ',' . $value ); // formats and removes duplicates
// Save new categories to album
wppa_update_album( array( 'id' => $alb, 'cats' => $new_cats ) );
}
Before doing this, pls read the instructions: https://wppa.nl/docs-by-subject/advanced-topics/custom-code/
For tags and cats: using the sanitize tags/cats functions is vital, as well as the removal of possible commas.
he logfile (Table VIII-A1) tells you what has been done.
—
To my knowledge, there is no ISO standard for IPTC tags, but more or less an agreement between vendors of photo editors.
I use this list: (See wppa-exif-iptc-common.php line 3105)
if ( $s == '2#005' ) $desc = 'Graphic name:';
if ( $s == '2#010' ) $desc = 'Urgency:';
if ( $s == '2#015' ) $desc = 'Category:';
if ( $s == '2#020' ) $desc = 'Supp categories:';
if ( $s == '2#040' ) $desc = 'Spec instr:';
if ( $s == '2#055' ) $desc = 'Creation date:';
if ( $s == '2#080' ) $desc = 'Photographer:';
if ( $s == '2#085' ) $desc = 'Credit byline title:';
if ( $s == '2#090' ) $desc = 'City:';
if ( $s == '2#095' ) $desc = 'State:';
if ( $s == '2#101' ) $desc = 'Country:';
if ( $s == '2#103' ) $desc = 'Otr:';
if ( $s == '2#105' ) $desc = 'Headline:';
if ( $s == '2#110' ) $desc = 'Source:';
if ( $s == '2#115' ) $desc = 'Photo source:';
if ( $s == '2#120' ) $desc = 'Caption:';
Note: The prefixes 2# for iptc and E# for exif is my addition to distinguish between the two types of hex numbers, and for the use as keywords in descriptions. They must be part of the data in the ‘tag’ column in both tables (wppa_exif and wppa_iptc).