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?
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?
Share Improve this question asked Aug 17, 2019 at 20:23 Rivero FelipeRivero Felipe 31 bronze badge1 Answer
Reset to default 0Is 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')
);