Meta Updater

"; print_r( $data ); echo ""; $header_row = array_shift( $data ); $search_field = $header_row[0]; $replace_field = $header_row[1]; print_r( $header_row ); print_r( $data ); echo "Search: $search_field, replace: $replace_field"; echo "

Results

"; $success = 0; foreach( $data as $row ) { $args = array( 'meta_key' => $search_field, 'post_type' => 'site' ); if ( is_string( $row[0] ) ) { $args['meta_value'] = $row[0]; } elseif ( is_numeric( $row[0] ) ) { $args['meta_value_num'] = $row[0]; } echo "

"; print_r( $args ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); echo get_the_title(); if ( $_POST['dry_run'] != '1' ) { echo "Updating meta for real"; if ( update_post_meta( get_the_ID(), $replace_field, $row[1] ) ) { $success++; } } } } else { echo "No results
"; } } echo "

Saved $success terms.

"; } ?>

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.