How to use mysql IN statement with wpdb update method?

I am using wpdb update method and wish to update records where the id is not found within multiple ids.

So if I wanted to update records where each had an id of 1 I would do for example:

Read More
$wpdb->update( 
            'wp_my_tables', 
            array( 
                'active' => 0
            ), 
            array( 'id' => 1 ), 
            array( 
                '%d'
            ), 
            array( '%d' ) 
        );

But how would I edit that so it does NOT update values where the ids are for example 1,2,3 ?

Related posts

Leave a Reply

1 comment

  1. You can run a generic query using $wpdb->query() and this might be easier in this case.

    $q = $wpdb->prepare( 'UPDATE wp_my_tables SET foo = %s WHERE id NOT IN (1, 2, 3)', array( 'bar' ) );
    
    $wpdb->query( $q );