I'm working on a WordPress project where I need to programmatically trigger the update of a post in the backend. The goal is to have WordPress process and update custom fields as if I had clicked the "Update" button in the post editor, but without actually changing any of the post data.
I tried using the wp_update_post function with just the post ID, but it didn't work as expected. Here is what I've tried:
function trigger_post_update($post_id) {
// Verify if the post exists
if (!get_post($post_id)) {
return;
}
// Trigger the update process by calling wp_update_post with the post ID only
wp_update_post(array('ID' => $post_id));
}
// Example usage: trigger the update for post with ID 1
trigger_post_update(1);
However, this code doesn't seem to trigger the update process properly for custom fields.
Question:
How can I programmatically trigger the update process for a post in WordPress so that custom fields and other related hooks are processed correctly, without changing the post data? please note that this problem is related to cron
Any help would be greatly appreciated!