Home » Php » php – WordPress post revisions not creating when updating a custom post type via WP REST API

php – WordPress post revisions not creating when updating a custom post type via WP REST API

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a few custom post types that have several custom fields created using ACF. I have enabled post revisions for the custom post type.

When I editing any field of a custom post using the admin dashboard and saving, the revision is created without any issues.

When I edit or update any field of the same post via WP REST API, the values are getting updated but revision history is not getting created.

It seems the only way revision history is created when using the dashboard and not via the REST API.

Is there a way to make it create revisions when updating or creating custom post type posts via REST API? Any hacks or hook I can use?

Thanks.

How to&Answers:

Try with this:

add_action('post_updated', 'wp_save_post_revision', 10);