How can i add to every new user who register this meta key…instead of updating all users to value 0 again..just to assign this meta key and value 0 to the new user who register
global $wpdb;
$users = $wpdb->get_results( "SELECT ID FROM $wpdb->users" );
if( $users ) {
foreach ( $users as $user ) {
update_user_meta( $user->ID, 'dospjeli_dug', 0 );
}
}
2
Answers
you can use hook for it.
user_register
hook will do it.add_action(‘user_register’,’addneumeta’, 10, 1);
If you want to add it to only new register user then according to documentation you need to use this function.