I’m building a wordpress website.
My question is:
How can I use (set & get) a persistent variable per user.
For example : I want to give the user a grade, and to keep it.
I cannot keep this data in session, because then when user leaves I will have to start over.
Also, I know I can use cookies, but I prefer to use the server side to keep this information.
Does anyone know a way to do so?
For custom user information like this wordpress has some functions that allows you to save the so called “custom meta” for each user. Check this functions in the wordpress codex:
update_user_meta ->this allows you to store/set the data in the MySql table. So if you want to say give the user a grade you just do:
update_user_meta( $user_id, "user_grade", "grade_value");
and wordpress will store the grade for that user.(you can store multiple values, check the codex that I’ve linked for details…).
get_user_meta -> this is used to get the user custom meta, or the data saved by
update_user_meta
as an example that will get the above saved value is:the last parameter helps you get multiple values, again, check the codex.