Hello,
i’ve created a custom field containing a number in the user profile.
Now i would like to reset this field to 0 at a certain date. I used this code but it seems that it doesn’t work. Any clues.
`
//Snippet azzeramento gettoni
$currentDate = date(‘Y-m-d’);
$currentDate=date(‘Y-m-d’, strtotime($currentDate));
$targetDate = date(‘Y-m-d’, strtotime(“06/05/2019”));
$gettoniRimanenti = (int) get_field(‘gettoni’);
if ($targetDate > $targetDate){
update_field(‘gettoni’, ‘0’, “user_5”);
}else{
echo “Not Today!”;
}
Thanks in advance
When is this code run? Is it run on every page load and does it look at every user?
Is this field also a user field or is it somewhere else? Shouldn’t it also tell acf what user to get the value from?
$gettoniRimanenti = (int) get_field('gettoni, 'user_5');
This would normally be something you’d need to set up in a cron task and you would need to read through every user and check each one.