Trying to work out how I could track the time that a field was updated and display that time on a page.
So far:
Using advanced custom fields and the options page the user updates some fields
What I’d like to be able to do
Capture the time this happens and output it onto a page
Why?
Each day the user is inputting prices (which effect all prices across the site) and would like a line that reads “prices correct as of …”
In Summary
So to sum it up, is it possible to track when this custom field is updated? Or any other ideas for tracking this event? I know I could put an extra field underneath where the user could input todays date and time but I’m trying to set up an automated failsafe system for them.
I don’t have to use advanced custom fields and I’m welcome to other ideas, but that’s what is set up currently so I was looking to integrate into it.
You can use the
acf_update_value
filter to set a post meta value whenever the field is updated.Here’s an example for a field named
test_field
. Check if the current field istest_field
, then get its old value and compare it to the new value. If it has been updated, update a post meta field named_update_time
with the current time. In your template, useget_post_meta
to output the time.Have a look through the ACF documentation for other filters and actions. There are also more general filters that run on all fields or just certain field types, as welll as this filter which is specific to a single field name.
EDIT-
I just noticed you said options page, not a post. To make this work with the options page, just change
update_post_meta
to instead update an option: