Posted By

hugosolar on 06/29/11


Tagged

wordpress update multisite wpoptions masive


Versions (?)

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


 / Published in: PHP
 

URL: http://www.hugosolar.net

  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');

Report this snippet  

You need to login to post a comment.