Hey guys, I have this points system on a project, everything works fine except that I can't add meta_values to multiple users.
I'm using <?php update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ) ?>
but this seems to not work with multiple users.
Any idea?
You can try something like;
Do you simply pass an array with user_ids to
update_user_meta
? Then it won't work indeed.Using a loop over all user_ids it should work:
Think about the SQL being generated, while keeping in mind the database design of WordPress. It has the table
wp_usermeta
, with columnsuser_id
,meta_key
andmeta_value
. That means that every meta value has a row in this table, for every user. You could use some code asHowever this would not work if the
meta_key
for a certain user does not exist yet. You would then need anINSERT
statement, which you can't do in a batch.