From 873c4fd166e4e5dac3af7276b10ba14558418c08 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Thu, 23 Apr 2015 16:24:05 +0100 Subject: [PATCH] First commit --- metaupdater.php | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 metaupdater.php diff --git a/metaupdater.php b/metaupdater.php new file mode 100644 index 0000000..9f0f68a --- /dev/null +++ b/metaupdater.php @@ -0,0 +1,114 @@ + +
+

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. +

+ + +

+

+
+ +