Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Functions
- function db_connect($host,$db,$user,$pass){
- if(@mysql_connect($host, $user, $pass)){
- @mysql_select_db($db)or
- $content = sql_debug();
- }
- else {
- $content = sql_debug();
- }
- return @$content;
- }
- // Variables to change
- $sql_username = "";
- $sql_password = "";
- $sql_host = "";
- $sql_db = "";
- // What is your post type that you want to limit this change to?
- // IE: Only posts from 'exhibitors' will have this change
- // $post_type = 'post_type';
- // What is the meta source? In this example it is website_link
- // this is the "old" value you want to copy to the new value
- $old_value = '_mds_';
- // What is the meta destination? In this example lets use tf_ex_site_url
- // BOTH key names must already exists in this instance of the script. If
- // both don't exist connected with the post_id, the value wont be copied.
- $new_value = '_yoast_wpseo_metadesc';
- // Ok Go
- db_connect($sql_host,$sql_db,$sql_username,$sql_password);
- $counter = 0;
- // Applies to everything.
- // OLD // $query = "SELECT * from wp_posts WHERE post_type = '$post_type'";
- $query = "SELECT * from wp_posts";
- $result = mysql_query($query);
- while ($row = mysql_fetch_array($result)) {
- $post_id = $row['ID'];
- $query2 = "SELECT * from wp_postmeta WHERE post_id = '$post_id'";
- $result2 = mysql_query($query2);
- while ($row2 = mysql_fetch_array($result2)) {
- // Do update here
- if ($row2['meta_key'] == $old_value) {
- $counter++;
- $temp_new = $row2['meta_value'];
- $query_update = "UPDATE wp_postmeta SET meta_value = '$temp_new' WHERE meta_key = '$new_value' AND post_id = '$post_id'";
- $result_update = mysql_query($query_update);
- // Un-comment the below line if you want to BLANK the old value (ie in this case make website_link = to nothing after
- // updating the value of tf_exhibitor_sort
- // mysql_query("UPDATE wp_postmeta SET meta_value = '' WHERE meta_key = '$old_value' AND post_id = '$post_id'");
- }
- }
- }
- echo $counter." records updated.";
- ?>
Add Comment
Please, Sign In to add comment