• Here’s an example code for a plugin I’m working on:

    if ( !empty( $_POST['save'] )) {
      // If the current number of revisions <= the maximum allowed revisions (3)
      if ( count( wp_get_post_revisions( $post_ID )) <= WP_POST_REVISIONS ) {
        // Save post revision
        wp_save_post_revision( $post_ID );
      }
    }

    The problem is wp_get_post_revisions always returns an empty array, and I don’t know why. I set WP_POST_REVISIONS to 3 in wp-config.php.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @josephyhu ,

    Could you please tell us, if you are doing this for a custom post type or default blog post type?

    If this is about a Custom Post type then please check if the support for ‘revisions’ is added while registering the Custom Post Type.

    Please let us know your feedback on this!

    Thread Starter Joseph Yhu

    (@josephyhu)

    Hi.

    It is for a custom post type, and yes the support for ‘revisions’ is added when registering the post type.

    Thread Starter Joseph Yhu

    (@josephyhu)

    Any help?

    Moderator bcworkz

    (@bcworkz)

    Be sure the post in question actually has revisions. Be sure your code is actually executing. If you still have trouble, the query for revisions is like any other post query — it can be altered by other code. The alteration could be inadvertent. Eliminate any possible influence by deactivating all plugins except your own and switch to twentytwenty theme. If you still have trouble, it could be from your own plugin. Deactivate your plugin and temporarily place test code on a theme template. You ought to get the expected revisions returned when all possible influence is removed.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_get_post_revisions always empty’ is closed to new replies.