Meta Updater

Results"; $success = 0; $not_found = []; foreach( $data as $row ) { list( $key, $value ) = $row; if ( $key == '' ) continue; // skip blank lines $args = array( 'meta_key' => $search_field, 'post_type' => 'site' ); // if ( is_string( $key ) ) { $args['meta_value'] = $key; // } elseif ( is_numeric( $key ) ) { // $args['meta_value_num'] = $key; // } echo "

"; $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); if ( $_POST['dry_run'] != '1' ) { if ( update_post_meta( get_the_ID(), $replace_field, trim( $value ) ) === true ) { echo "

";
              print_r( $args );
              echo sprintf( "ID: %d
%s: %s
Title: %s
%s: %s", get_the_ID(), $search_field, $key, get_the_title(), $replace_field, $value ); $success++; } } } } else { $not_found[]= $key; echo "No results
"; } } echo "

Updated $success custom fields OK.


"; echo "

Errors

"; if ( count( $not_found) > 0 ) { echo "

Posts with the custom field $search_field with these values could not be found:

\n"; } else { echo "

None.

"; } } ?>

Paste in CSV data: column 1 holds the key field and column 2 holds the value. The first row must be a header row. Every post with the field set to the value in column 1 will have a field added or updated with the value in column 2.