1

wordpress always store revision after call wp_update_post. How to get the post revision ID after call wp_update_post?

Thanks

1

You can use wp_get_post_revisions.

<?php
// some logic here

$post_id = wp_update_post(/* ... */);
$latest_revision = array_shift(wp_get_post_revisions($post_id));

if ($latest_revision) {
   // do stuff with the latest revision
   // $latest_revision->ID will contain the latest revision
}
| improve this answer | |
  • I think you meant array_shift, and NOT array_unshift. So it would be: $latest_revision = array_shift(wp_get_post_revisions($post_id)); – ColdTuna Jul 17 '15 at 23:18
  • Good catch, changed! – chrisguitarguy Jul 18 '15 at 1:07
  • 1
    Note that array_shift() rebuilds the array index. It is rather slow. Since you don't need that array later, you could just use current(). – fuxia Jul 18 '15 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.