I don't know what are you trying to achieve, but in my mind and opinion, you are definitely on the wrong track here.
When a custom field is updated, nothing happens to the actual post object as custom fields aren't part of the WP_Post
object. This means that no actions are triggered related to updating the post object itself, and therefor the post_modified
and post_modified_gmt
dates remain the same. This all comes down to that you cannot use the post object as a guideline as to when a custom field was updated. For the sake of interest, be sure to read this answer by @gmazzap about which hooks firing when a post is updated
Custom fields by itself also does not save any info about creation, deletetion or modified dates and times. For this you will need to write your own API and somehow store these relevant dates in db, and then call upon these saved dates for checking purposes before what you are suppose to run on success and failure.
You will most probably need to look at hooks like updated_post_meta
which fires after a custom field is successfully updated and then act on that to update some value in some field which is created by your own API. You can also check out this answer by @JanFabry about all relevant functions and actions regarding custom fields
TO CONCLUDE
I wonder if it is even worth the trouble writing an extensive API for this. You will first need to go and rethink your complete approach to this, and if you really need to do this with custom fields, you will need to write an API which will handle the complete CRUD process reliably and safely
EDIT
To avoid confusion and probably wrong interpretation, we are talking about updating a custom field, which in the sense of this post means that we only click the Update button in the Custom Fields meta box. By only clicking that Update button, nothing happens to the post and the modified dates stay the same.
The modified dates only changes when we explicitly click on the Update button in the Publish meta box. Although the post object doesn't change, the post modified dates are updated as if the post object has changed. Just remember, we do not need to click this Update button to update a custom field, which makes any method relying on this as a custom field updated very unreliable
modified_date
orthe_modified_date()
function in the loop to get when it was updated. Unless of course you're updating postmeta via ajax or some other method.