Replace fields siteurl and home in wp_options tables in a wordpress multisite


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function update_tables() {
  2. global $wpdb;
  3. for ($x=0;$x<=216;$x++): //limit for to the last blog_id created
  4. $table='wp_'.$x.'_options';
  5. $existe= $wpdb->get_results('SELECT * FROM '.$table.'');
  6.  
  7. if ($existe)
  8. foreach($existe as $entry):
  9. if ($entry->option_name=='siteurl') {
  10. $siteurl=str_replace('my.old.url','my.new.url',$entry->option_value);
  11. $wpdb->update( $table, array('option_value'=>$siteurl), array('option_id' => $entry->option_id) );
  12. }
  13. if ($entry->option_name=='home') {
  14. $home=$entry->option_value;
  15. $home=str_replace('my.old.url','my.new.url',$entry->option_value);
  16.  
  17. $wpdb->update( $table, array('option_value'=>$home), array('option_id' => $entry->option_id) );
  18. }
  19.  
  20.  
  21. endforeach;
  22. endfor;
  23. }
  24.  
  25. add_action('init','update_tables');

URL: http://www.hugosolar.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.