• add_user_meta( int $user_id, string $meta_key, mixed $meta_value, bool $unique = false )

    Hello guys, I am an amateur in both WordPress and php. I am working on user meta data, I want to add user meta data that stores (number) integers to the user.php on my site.
    I want the default number to be 0,
    I know the above code is required but I need help with that.
    And I don’t understand the $user-id part because I want the meta data for every user when they sign up

Viewing 3 replies - 1 through 3 (of 3 total)
  • The $user_id would be the ID of the user’s record in the user table.
    The $meta_key is what you are calling this data, such as ‘theUserNumber’.
    The $meta_value is the actual number, such as 0.
    The $unique is true or false depending on whether there are more than one of these per user.

    Thread Starter sunmoluvic

    (@sunmoluvic)

    Thanks for your reply @joyously
    And I’m sorry, I’m only trying to learn because I’m new to php

    What I’m trying to say is that $user-id is meant to be for all user not for one user, how do I do that?

    User meta is for storing something per user. If you want to store a single number that is counting users, then you wouldn’t store it in user meta. And if it’s counting, it’s better to just ask the database how many there are when you need it.
    For a single number, you can create an option, instead of user meta.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I need help with user meta data’ is closed to new replies.