Jump to content

Wordpress Update SQL Query


jarvis

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.