Support

Account

Home Forums ACF PRO update_field date field not displaying date on the admin front-end

Solving

update_field date field not displaying date on the admin front-end

  • Hi, I’m using two date fields, start_date and end_date attached to a custom post type.

    If i update these values via datepicker in edit post and update, the page refreshes and the values are displayed in the input box.

    If however, i update these values via update_field, the values are not displayed in the edit post but our displayed when i run the_field().

    Why are they not updating with update_field?

    Thanks!

    start_date : field_559cfc4e569e7 : date : display/return format – 09/07/2015
    end_date : field_559cfccc569e8 : date : display/return format – 09/07/2015

    update_field('field_559cfc4e569e7', '15/07/2015', 329);
    update_field('field_559cfccc569e8', '01/08/2015', 329);
    
    echo "ID: " . get_field('field_559e476721c58', 329) . "<br>";
    echo "START DATE: " . get_field('field_559cfc4e569e7', 329) . "<br>";
    echo "END DATE: " . get_field('field_559cfccc569e8', 329);

    OUTPUTS:

    ID: even:aaf-ib2c7v99-n4cd1e
    START DATE: 15/07/2015
    END DATE: 08/01/2015

  • No matter the return or display format, ACF stores dates in the format YYYYMMDD. When you update the field you need to use that format. Most likely the value is not shown in the admin because it’s saved in a format it does not understand.

    • tgnsd

    • January 19, 2016 at 7:24 am

    Just to clarify, use date('Ymd') not date(‘YYYYMMDD’)

  • I was showing the way it was stored, not the PHP date format value. The code that was in question was update_field('field_559cfc4e569e7', '15/07/2015', 329); which did not use the PHP date() function. I did not know how that date was being generated and did not want to assume anything.

  • Woohoooo! 10pm at night and I was about to give up – why the hell could I not get the right date added when in acf settings I had the date in the ‘d/M/Y’ format.

    This is WHYYYY!

    Thanks!

  • Just jumping on this for advice.

    I’m trying to calculate a date (review date – 7 days = reminder date)

    so I have 2 ACF fields:
    – document_review_date
    – document_review_date_reminder_trigger

    In my function, I have:

    $reviewDate = get_field(document_review_date);
    $remindDate = date("Ymd", strtotime($reviewDate . '-7 days'));
    update_field(document_review_date_reminder_trigger, $remindDate);

    $remindDate is returning the correct calculated date.

    However, it doesn’t seem to be updating my ACF field as it is not shown in the field in the post editor.

    What am I doing wrong here?

  • is that the actual code? The field name should be in quotes

    
    update_field('document_review_date_reminder_trigger', $remindDate);
    

    You may need to provide the post ID

    
    update_field('document_review_date_reminder_trigger', $remindDate, $post_id);
    
  • Hmmm, I had tried it with quotes also. Either way, with or without the quotes, it reads the field OK and does the calculation as expected.

    I also read somewhere (forgotten where, amongst all the Googling!) that with date types, the field key should be used instead of the field name.

    Field name, field key, with and without quotes, the update field doesn’t seem to write data and the field remains blank.

    I tried also adding $post_id too, although I believe this defaults to the current post anyway.

    $reviewDate = get_field('document_review_date');
    $remindDate = date("Ymd", strtotime($reviewDate . '-7 days'));
    update_field('field_60f4466dcddc8', $remindDate, $post_id);
  • What did you do to get it to work? I’ve still not managed to get this to work at all.

  • @leem2209 it appears you were replying to spam.

    Looking at your code and what you tried I don’t see what the issue could be.

    The only thing that I can come up with is if you are trying to get the value right after updating it that the old value could be caught in the cache.

    Is the value actually being updated in the DB?

Viewing 10 posts - 1 through 10 (of 10 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.