0

I need to update user meta from php file on my server. Maybe I need some additional permissions?

<?php
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
$user_id = 1;
$new_value = 'http://wordpress.org';
// will return false if the previous value is the same as $new_value
update_user_meta( $user_id, 'website', $new_value );
// so check and make sure the stored value matches $new_value
if ( get_user_meta($user_id,  'some_meta_key', true ) != $new_value )
wp_die('An error occurred');
?>

This shows 'An error occured' and user meta is not updated.

2
  • Well, the meta keys don't match - you're updating website, but then checking for some_meta_key.
    – Sally CJ
    Commented Jan 26, 2019 at 10:02
  • You are setting one meta value “website” but you are checking a different meta value “some_meta_key”.
    – dsj
    Commented Jan 27, 2019 at 2:00

0

Your Answer

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

Browse other questions tagged or ask your own question.