Im trying to update into another table the values blogname, blog description options when the user updated them from General Settings page.

I use this code,

$hook_array = array('update_option_blogname','update_option_admin_email','update_blogdescription','update_option_home','update_option_siteurl');

foreach($hook_array as $hook)
    add_action($hook, 'my_functione', 10, 1);


function my_functione($arg)
    global $wpdb;
    $the_id = get_current_blog_id();
    $blogname =  get_option('blogname'); 
    $blogdescr =  get_option('blogfulldescription');
    $wp_blogs_info = $wpdb->base_prefix . "blogs_info";

    $wpdb->query("UPDATE " . $wp_blogs_info . " SET site_title=".$blogname.", site_description=".$blogdescr." where blog_id = '" . (int)$the_id . "'");


Here is the table,

  blog_id int NOT NULL,
  countries_id int(3) NOT NULL,
  site_title varchar(64) NOT NULL,
  site_description varchar(64) NOT NULL,
  site_tags varchar(64) NOT NULL,
  PRIMARY KEY (blog_id)

However, its not updating though there is a value with the blog_id of the current blog.. Please help.

  • what is the outcome? do you get any error or message? – HungryCoder Jun 19 '12 at 7:12

well, i just found that you've error in your query. i've re-written that for you:

$wpdb->query("UPDATE `" . $wp_blogs_info . "` SET `site_title`='".$wpdb->escape($blogname)."', `site_description` = '".$wpdb->escape($blogdescr)."' where blog_id = '" . (int)$the_id . "'");
| improve this answer | |
  • Thank you! it works now. I didn't knew the escape one. – Ken Jun 19 '12 at 7:56
  • not only escaping, you did not put the quotation sign around the values. – HungryCoder Jun 19 '12 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.