Guest User

Untitled

a guest
Apr 19th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.01 KB | None | 0 0
  1. <?php
  2. // Functions
  3. function db_connect($host,$db,$user,$pass){
  4.   if(@mysql_connect($host, $user, $pass)){
  5.     @mysql_select_db($db)or
  6.     $content = sql_debug();
  7.   }
  8.   else {
  9.     $content = sql_debug();
  10.   }
  11.   return @$content;
  12. }
  13.  
  14. // Variables to change
  15. $sql_username = "";
  16. $sql_password = "";
  17. $sql_host = "";
  18. $sql_db = "";
  19.  
  20. // What is your post type that you want to limit this change to?
  21. // IE: Only posts from 'exhibitors' will have this change
  22. // $post_type = 'post_type';
  23.  
  24. // What is the meta source? In this example it is website_link
  25. // this is the "old" value you want to copy to the new value
  26. $old_value = '_mds_';
  27.  
  28. // What is the meta destination? In this example lets use tf_ex_site_url
  29. // BOTH key names must already exists in this instance of the script. If
  30. // both don't exist connected with the post_id, the value wont be copied.
  31. $new_value = '_yoast_wpseo_metadesc';
  32.  
  33. // Ok Go
  34. db_connect($sql_host,$sql_db,$sql_username,$sql_password);
  35. $counter = 0;
  36. // Applies to everything.
  37. // OLD // $query = "SELECT * from wp_posts WHERE post_type = '$post_type'";
  38. $query = "SELECT * from wp_posts";
  39. $result = mysql_query($query);
  40. while ($row = mysql_fetch_array($result)) {
  41.   $post_id = $row['ID'];
  42.   $query2 = "SELECT * from wp_postmeta WHERE post_id = '$post_id'";
  43.   $result2 = mysql_query($query2);
  44.   while ($row2 = mysql_fetch_array($result2)) {
  45.     // Do update here
  46.     if ($row2['meta_key'] == $old_value) {
  47.       $counter++;
  48.       $temp_new = $row2['meta_value'];
  49.       $query_update = "UPDATE wp_postmeta SET meta_value = '$temp_new' WHERE meta_key = '$new_value' AND post_id = '$post_id'";
  50.       $result_update = mysql_query($query_update);
  51.       // Un-comment the below line if you want to BLANK the old value (ie in this case make website_link = to nothing after
  52.       // updating the value of tf_exhibitor_sort
  53.       // mysql_query("UPDATE wp_postmeta SET meta_value = '' WHERE meta_key = '$old_value' AND post_id = '$post_id'");
  54.     }
  55.   }
  56. }
  57.  
  58. echo $counter." records updated.";
  59.  
  60. ?>
Add Comment
Please, Sign In to add comment