WordPress wpdb update not working

$wsquery = array( 'faculty_id' => $uid);
$tid = array('id'=>1);
$tname = 'imtd_faculty_in_focus';
$wpdb->update( $tname, $wsquery , $tid);

This is my update code;
But evertime it returns Fatal error: Call to a member function update() on null

all values are set.

Related posts

1 comment

  1. Fatal error: Call to a member function update() on null

    According to the error -$wpdb is undefined.

    My guess is that you’re using this code in a function.
    If this is the case, you should add the following line in order to use this class in your function:

    global $wpdb;
    

    So your code should look like:

    function anon_function($uid) {
     global $wpdb;
    
     $wsquery = array( 'faculty_id' => $uid);
     $tid = array('id'=>1);
     $tname = 'imtd_faculty_in_focus';
     $wpdb->update( $tname, $wsquery , $tid);
    }
    

Comments are closed.