Home Forums ACF PRO update_sub_field updates all values in column


update_sub_field updates all values in column

  • Hey,

    I’m trying to use update_sub_field to set my ‘active’ field to false if today’s date has passed the date in the same row. But whenever this is the case it updates all the ‘active’ fields and sets them to false. Below is the code i’m using:

    $today = date("d-F-Y");
    $today_time = strtotime($today);
    while ( have_rows('data') ) : the_row();
        $date = strtotime(get_sub_field('date'));
        if ($today_time > $date) {
            update_sub_field('active', false);

    Can you help me figure out what i’m doing wrong?

  • I’ve looked into this and the only thing that I can come up with is that $date = strtotime(get_sub_field('date')); is not evaluating to the right value. What is the day format that’s being returned for that field?

  • Thanks for the reply.

    I’ve used the format d MM yy for the subfield ‘date’.

  • I think that is you problem. For example if I use php to do this for today’s date in that format $date = strtotime('21 20 15'); nothing is returned. So $today_time is always >

    Try this $date = strtotime(get_sub_field('date', false, false));

    The second false tells ACF not to format the value so it will be returned as ‘YYYYMMDD’ and this is interpreted correctly by strtotime()

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

The topic ‘update_sub_field updates all values in column’ is closed to new replies.