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:

Read More
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' ");

Related posts

2 comments

  1. 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'
    
  2. 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")
    

Comments are closed.