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?
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);
START DATE: 15/07/2015
END DATE: 08/01/2015
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.
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:
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?
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);
@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?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.