jarvis Posted July 19, 2016 Share Posted July 19, 2016 Hi All, I'm possibly being daft (I blame the heat!). I have the following 2 statements: #Update Site Title $wpdb->show_errors(); $wpdb->update( $table, $data, $where ); $wpdb->update( $wpdb->options, array( 'option_name' => 'blogname', 'option_value' => 'NEW BLOG NAME', 'autoload' => 'yes' ), array( "option_id", $option_id ) ); $wpdb->print_error(); var_dump( $wpdb->last_query ); #Update Site Wide Description $wpdb->show_errors(); $wpdb->update( $table, $data, $where ); $wpdb->update( $wpdb->options, array( 'option_name' => 'blogdescription', 'option_value' => 'MAIN SITE DESCRIPTION GOES HERE', 'autoload' => 'yes' ), array( "option_id", $option_id ) ); $wpdb->print_error(); var_dump( $wpdb->last_query ); As both reside in the same table (options), do I have to run them as separate statements OR is there a way I can run both in one statement? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/301512-wordpress-update-sql-query/ Share on other sites More sharing options...
maxxd Posted July 21, 2016 Share Posted July 21, 2016 option_id is the primary key in the table, so I'd think running the queries separately is the way to go. However, I'm wondering why you're running another update using $table, $data, and $where right before you run the updates you're asking about. Nowhere in the code you've posted are $table, $data, or $where actually set. So it is possible that you can cut half the update calls depending on the contents of those variables. Quote Link to comment https://forums.phpfreaks.com/topic/301512-wordpress-update-sql-query/#findComment-1534758 Share on other sites More sharing options...
jarvis Posted July 21, 2016 Author Share Posted July 21, 2016 Thanks @maxxd, $wpdb->update( $table, $data, $where ); should be commented out - it's for my ref only. Sorry! Thanks for your help though, I think I may leave them as separate queries to run as easier to work with etc. Quote Link to comment https://forums.phpfreaks.com/topic/301512-wordpress-update-sql-query/#findComment-1534775 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.