Support

Account

Home Forums General Issues Reset custom field at target date

Helping

Reset custom field at target date

    • mikbio

    • May 7, 2019 at 10:20 pm

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.