[wp-hackers] changing a theme via wpdb class

Dion Hulse (dd32) wordpress at dd32.id.au
Mon Apr 30 05:39:10 UTC 2012


This code also never had a chance of working, pay close attention to
the args of update() and the database schema you're updating. It's not
designed to work in the way you attempted to use it.
http://codex.wordpress.org/Class_Reference/wpdb#UPDATE_rows

The correct usage would've been something like this for each option
you wanted to apply to:
$wpdb->update( $wpdb->options,
  array( 'option_value' => $newtheme ), // new row data
  array( 'option_name' => 'template' ) // the WHERE clause for which
row to affect
);

That's just a quick lesson on $wpdb->update() since no-one seemed to
pick up on it :)
However, like everyone has already mentioned, there are far better
ways to achieve what you were trying..


On 30 April 2012 03:59, Chris McCoy <chris at lod.com> wrote:
> 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


More information about the wp-hackers mailing list