0
wp --ssh=barrycar@bc4 --path=public_html/wordpress --fields=ID,post_title,post_name,post_date,post_status,post_author,post_parent,post_type,filter,guid,menu_order,post_content --format=yaml post list

I used the command above to download all posts on my WordPress blog. I'd like to know which version of a given post is live on the site. Relevant portion of YAML output:

-
  ID: 22371
  post_title: Albuquerque Street Names
  post_name: 13019-revision-4
  post_date: 2012-03-06 03:00:53
  post_status: inherit
  post_author: 2
  post_parent: 13019
  post_type: post
  filter: raw
  guid: http://wordpress.barrycarter.org/index.php/2012/03/06/13019-revision-4/
  menu_order: 0
  post_content: [...]
-
  ID: 22370
  post_title: Albuquerque Street Names
  post_name: 13019-revision-4
  post_date: 2011-11-24 16:47:32
  post_status: inherit
  post_author: 2
  post_parent: 13019
  post_type: post
  filter: raw
  guid: http://wordpress.barrycarter.org/index.php/2011/11/24/13019-revision-4/
  menu_order: 0
  post_content: [...]
- 
  ID: 13019
  post_title: Albuquerque Street Names
  post_name: albuquerque-street-names
  post_date: 2011-09-03 03:38:21
  post_status: publish
  post_author: 2
  post_parent: 0
  post_type: post
  filter: raw
  guid: http://wordpress.barrycarter.org/?p=13019
  menu_order: 0
  post_content: [...]

If I had to guess, I'd say ID 22371 is the version that's live on the site, because:

  • It has the highest ID of the three

  • It ties for highest "revision" (revision-4) of the three

  • It has the latest post_date of the three

However, this seems indirect. What's the correct way of finding which is the currently published version? Related questions:

  • What filter gives me only live current posts? --post-status=publish seems like it'll give me the first version of each post.

  • Why are there two 13019-revision-4 and no 13019-revision-3 or 13019-revision-2 for example?

0

Answering my own question, the current revision has these properties as compared to revisions:

  • The post_status will be "publish" not "inherit".
  • The post_parent will be 0
  • The post_type will be "post" not "revision".

Additionally, the ID of the current revision doesn't change when you update the post; instead, the older version is given a new ID.

Example:

  • I created a post called "test post" with content "this is revision one.". It was assigned ID 28623. When I did "wp post get 28623", the interesting part of the output was:

ID      28623
post_date       2017-12-13 16:26:02
post_content    this is revision one.
post_title      test post
post_status     publish
comment_status  open
ping_status     open
post_name       test-post
post_modified   2017-12-13 16:26:02
post_parent     0
post_type       post
  • I then edited the content to read "this is revision two" and did "wp post get 28623" again. The results this time:

ID      28623
post_date       2017-12-13 16:26:02
post_content    this is revision two.
post_title      test post
post_status     publish
comment_status  open
ping_status     open
post_name       test-post
post_modified   2017-12-13 16:28:47
post_parent     0
post_type       post

Notice that post id 28623 itself has changed fields, and the live version if still id 28623. The post_date remains the same but the post_modified has changed.

What happened to the old version? I did "wp post get 28624". The results:


ID      28624
post_date       2017-12-13 16:26:02
post_content    this is revision one.
post_title      test post
post_status     inherit
comment_status  closed
ping_status     closed
post_name       28623-revision-v1
post_modified   2017-12-13 16:26:02
post_parent     28623
post_type       revision

The old version has been copied to a new row in the database. Note that there's no guarantee that the revision will have the ID immediately following the original post's id: wordpress will just use the next available id (it worked in my case because I didn't make any posts between the post and its revision).

  • Additionally:

    • the post_status is now "inherit", not "publish"

    • the post_type is "revision" not "post"

    • the post_parent is 28623, not 0

    • the post_name has changed to "28623-revision-v1" instead of "test-post", and no longer references the title. If the original post is at "(something)/test-post", you might be tempted to visit "(something)/28623-revision-v1" to see the revision. However, WordPress will yield a "page not found" error, since it doesn't allow end users to see revisions.

    • the post_modified is still equal to the post_date, since this was the original version

    • the "comment_status" and "ping_status" are now closed, since it wouldn't make sense to comment on or ping a revision. Of course, live posts can also have these both be "closed", but, if you allow comments/pings on a post, that permission will automatically be removed for older revisions.

  • I then reverted back to the original version, and did "wp post get 28623" to get:


ID      28623
post_author     1
post_date       2017-12-13 16:26:02
post_content    this is revision one.
post_title      test post
post_status     publish
comment_status  open
ping_status     open
post_name       test-post
post_modified   2017-12-13 16:46:20
post_type       post

Notice that the post has now returned to the original version, with one exception: the post_modified date no longer matches the post_date. In other words, if you modify a post and then modify it back, that's considered two modifications, not an undo of a modification (you can see this in the admin interface by noticing the "revisions" count is now 3, not 1 or 2).

Another way to see this is to do "wp post get 28624":


ID      28624
post_date       2017-12-13 16:26:02
post_content    this is revision one.
post_title      test post
post_status     inherit
comment_status  closed
ping_status     closed
post_name       28623-revision-v1
post_modified   2017-12-13 16:26:02
post_parent     28623
post_type       revision

Notice that, even though we've reverted to version 1, a separate copy of version 1 exists as a revision. Version 2 was given a new id as we see by doing "wp post get 28625".


ID      28625
post_date       2017-12-13 16:28:47
post_content    this is revision two.
post_title      test post
post_status     inherit
comment_status  closed
ping_status     closed
post_name       28623-revision-v1
post_modified   2017-12-13 16:28:47
post_modified_gmt       2017-12-13 16:28:47
post_parent     28623
post_type       revision

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.