Comments on: How to Create and Use WordPress User Metadata (User Meta) https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/ A hub for advanced WordPress users, developers & savvy business owners. Sat, 04 Apr 2020 17:36:47 +0000 hourly 1 https://wordpress.org/?v=6.4.3 By: Michal Sakulic https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21549 Sat, 04 Apr 2020 17:36:47 +0000 https://wpshout.com/?p=19311#comment-21549 Thank you for nice article. I have experienced this:

If I use

add_user_meta(get_current_user_id(),’video_history’,”fero”);

and save it into single.php, oen a any blog post, I see adding one value “fero” into video_history user meta, which is working as expected.

If you open another post you save two values of “fero” into meta array.

Do you thing it is bug?

]]>
By: Anita https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21548 Thu, 05 Mar 2020 12:42:00 +0000 https://wpshout.com/?p=19311#comment-21548 In reply to Fred Meyer.

Thanks for your help. My code was not actually being called. I went the route you suggested and once I’d actually registered the function it ran without problem.

]]>
By: Anita https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21547 Fri, 28 Feb 2020 17:03:00 +0000 https://wpshout.com/?p=19311#comment-21547 In reply to Fred Meyer.

Thanks Fred, I’ll have a play with it over the weekend.
My php code often ends up being a mixture of php, PL/SQL and Java syntax!

Anita

]]>
By: Fred Meyer https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21546 Fri, 28 Feb 2020 16:43:49 +0000 https://wpshout.com/?p=19311#comment-21546 In reply to Anita.

Thanks, Anita. At a glance, that code looks like it should do what you think.

A quick-and-dirty alternative is to register a function that listens for a query string:

function maybe_do_something() {
    if( ! isset( $_GET['iwanttodosomething'] ) ) :
        return;
    endif;

    // Do thing
} 

Then just go to yoursite.com/wp-admin/?iwanttodosomething to run the code.

In either case, I’d suggest lots of var_dumps to see if your code is actually running, and go from there.

Hope that helps!

]]>
By: Anita https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21545 Fri, 28 Feb 2020 11:27:43 +0000 https://wpshout.com/?p=19311#comment-21545 Hi,
I have over 1600 user meta items that I need to insert once, as part of a data migration. I have tried to implement this as part of the register_activation_hook in a site plugin. My thinking being that when I activate the plugin, the user meta gets inserted, and then I can deactivate and delete the plugin. Future maintenance is to be handled by a third-party plugin. But I can’t make it work.

My code is below. At a quick look, can you see anything wrong with it, or is there a better way to call it than from the plugin activation?

class essaUserMeta
{
final public function __construct()
{
register_activation_hook( __FILE__, array(‘essaUserMeta’,’user_meta_statements’) );
}
#
# CLASS METHODS
public static function user_meta_statements()
{
update_user_meta( 302, ‘mobile_phone_number’, ’07nnn nnnnnn’ );
# plus 1600+ other statements generated from the database
}
} # end class essaUserMeta
?>

]]>
By: gear https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21544 Sun, 02 Feb 2020 00:27:12 +0000 https://wpshout.com/?p=19311#comment-21544 I learned something I didn’t know before and I built my first plugin. I am on my way to becoming a journeyman developer. thank you.

]]>
By: Fred Meyer https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21543 Sun, 19 Jan 2020 18:07:02 +0000 https://wpshout.com/?p=19311#comment-21543 In reply to JUDY OOSTHUIZEN.

Thanks so much! I’ve fixed that typo.

]]>
By: JUDY OOSTHUIZEN https://wpshout.com/how-to-create-and-use-wordpress-user-metadata-user-meta/#comment-21542 Fri, 17 Jan 2020 15:54:13 +0000 https://wpshout.com/?p=19311#comment-21542 Think you using the wrong “update_post_meta( $user_id, $meta_key, $meta_value, $prev_value );” in your documentations, shouldnt it be “update_user_meta()” under – ADDING OR CHANGING WORDPRESS USER META DATA: UPDATE_USER_META()

Sorry I am wrong…

]]>