0

I am working in a wordpress site, I started to work in local enviroment using xampp server.

I used wpdb to do operations with the database like this:

global $wpdb;   

$name = $wpdb->get_results("SELECT meta_value FROM wp_usermeta WHERE meta_key = 'first_name' AND user_id = ".$user." ");

    $wpdb->update( 
    'wp_usermeta', 
    array( 
        'meta_value' => $v1 
    ), 
    array( 'user_id' => $user, 'meta_key' => 'first_name'  ), 
    array( 
        '%s'
    ), 
    array( '%d', '%s') 


);

In local enviroments works perfectly but when I migrated the project to an amazon instance, Ubuntu server using nginx and all the operations using $wpdb are not working.

I cant update, I cant insert.

I dont know why.

Any clue?

1 Answer 1

0

Is there a compelling reason to use $wpdb for this, and not the API functions get_user_meta() and update_user_meta()?

That said, here's something to check: Are you sure that your database prefixes on the server are wp_? If they're not, then your code won't work as expected.

Try this:

global $wpdb;   

$name = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}usermeta WHERE meta_key = 'first_name' AND user_id = ".$user." ");

    $wpdb->update( 
    $wpdb->prefix . 'usermeta', 
    array( 
        'meta_value' => $v1 
    ), 
    array( 'user_id' => $user, 'meta_key' => 'first_name'  ), 
    array( 
        '%s'
    ), 
    array( '%d', '%s') 


);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.