user3492381
user3492381

Reputation: 167

Update two row in wordpress sql

I need to update 2 row in wordpress sql database, I need change option_name 'stylesheet' value to 'twentyfifteen' and change option_name 'template' value to 'twentyfifteen'

This code is working:

global $wpdb;
$wpdb->query(" UPDATE $wpdb->options SET option_value = 'twentyfifteen' WHERE option_name = 'template' ");
$wpdb->query(" UPDATE $wpdb->options SET option_value = 'twentyfifteen' WHERE option_name = 'stylesheet' ");

But I need it in one line, like this but not working with me:

global $wpdb;
$wpdb->query(" UPDATE $wpdb->options SET option_value = 'twentyfifteen' WHERE option_name = 'template',
    UPDATE $wpdb->options SET option_value = 'twentyfifteen' WHERE option_name = 'stylesheet' ");

Upvotes: 1

Views: 85

Answers (2)

Anton Ohorodnyk
Anton Ohorodnyk

Reputation: 883

When you want update two lines by 1 request, you can use query like that:

UPDATE options
SET option_value = "twentyfifteen"
WHERE option_name in ("stylesheet", "template")

Upvotes: 1

juergen d
juergen d

Reputation: 204746

UPDATE $wpdb->options 
SET option_value = 'twentyfifteen' 
WHERE option_name in ('template', 'stylesheet')

or

UPDATE $wpdb->options 
SET option_value = 'twentyfifteen' 
WHERE option_name = 'template'
OR option_name = 'stylesheet'

Upvotes: 4

Related Questions