We are able to make use of ajax to update our post_meta as we wanted. However, it does not change the modified_time of the post.
We depend on the get_modified_time to show users when the post was last updated. (The newer the better)
I have searched around, and I don’t see anyone using this technique yet.
Does anyone have an answer?
Thanks!
I used wpdb::query() to do this:
Note: You can’t use
wp_update_post()
if you want to explicity set the modified date(s) on the post, because it calls wp_insert_post(), which determines that the post exists and sets the post_modified and post_modified variables to the current date.Very simple in PHP, where
80
is the post number:If you want to change for set of posts, better use Query Loop to get each post id.
Assuming that you have previously collected the post ID from your ajax request you can then update
post_modified
andpost_modified_gmt
using the regularwp_update_post
function:Resources
https://developer.wordpress.org/reference/functions/wp_update_post/