[wp-hackers] changing a theme via wpdb class

William P. Davis will.davis at gmail.com
Sun Apr 29 18:05:41 UTC 2012


You wouldn't want to do this on init - it will run those queries on every page load, which is massively inefficient. And you wouldn't use $wpdb's update wrapper to change the options table, you want the update_option function. 

If you want to change themes, I would recommend the switch_theme function: http://codex.wordpress.org/Function_Reference/switch_theme

I'm not sure how you're triggering this, but you only want to do it once (such as on plugin activation)
------Original Message------
From: Chris McCoy
Sender: wp-hackers-bounces at lists.automattic.com
To: wp-hackers at lists.automattic.com
ReplyTo: wp-hackers at lists.automattic.com
Subject: [wp-hackers] changing a theme via wpdb class
Sent: Apr 29, 2012 1:59 PM

function change_theme_manually() {
        global $wpdb;
        $newtheme = 'twentyeleven';
        $wpdb->update($wpdb->options,
                array('template'=> $newtheme),
                array('stylesheet'=> $newtheme),
                array('current_theme' => $newtheme)
        );
}


add_action('init','change_theme_manually');

can someone tell me what is wrong with this?

Doesn't seem to update the options



_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

Sent from my BlackBerry


More information about the wp-hackers mailing list