After seeing some weird hits in my Relevanssi search results I found the following:


I ran the following on my WordPress database:

SELECT * FROM  `wp_posts` 
  WHERE (`post_name` LIKE "%revision%" OR `post_name` LIKE "%autosave%")
  AND `post_status` = "inherit"
  AND `post_parent` !=0
  AND `post_type` !=  "revision"

It returned almost 2,000 rows. This means that many of the "revision" records in my wp_posts table are ending up with the wrong post type.

http://codex.wordpress.org/Revision_Management currently states the following:

Revisions are stored as children of their associated post (the same thing we do for attachments). They are given a post_status of 'inherit', a post_type of 'revision', and a post_name of {parent ID}- revision(-#) for regular revisions and {parent ID}-autosave for autosaves.

In my case these revision records are maintaining the original post type such as "page" or "my-custom-post-type" instead of being changed to "revision."

Any ideas why these records have the wrong post type? I read it may have to do with my custom post type definitions, but if so, why is it happening with "page" records as well?

  • This should not be happening, could you tell us what plugins you have activated and what theme, and if any of them have been modified/customised from their originals?
    – Tom J Nowell
    Mar 29, 2012 at 17:38
  • I created a listing of active plugins here: gist.github.com/2242493. In addition I had the "Post Type Switcher (1.0)" plugin active until recently. Mar 29, 2012 at 19:21
  • 1
    It looks like it's the Post Type Switcher plugin. Boo. When that plugin is activated, the revisions get saved with the original post type. When I deactivated the plugin and updated a post, the "revision" post type was correctly applied. Mar 29, 2012 at 19:58

2 Answers 2


Have you tried adding an extra clause checking for the revision post type in function pts_save_post( $post_id, $post ) { of post-type-switcher.php ?

E.g. as taken from trunk and modified:

 * Set the post type on save_post but only when editing
 * @since PostTypeSwitcher (0.3)
 * @global string $pagenow
 * @param int $post_id
 * @param object $post
 * @return If any number of condtions are met
function pts_save_post( $post_id, $post ) {
    global $pagenow;

    // Only show switcher when editing
    if ( ! in_array( $pagenow, pts_allowed_pages() ) )

    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )

    if ( ! isset( $_POST['pts-nonce-select'] ) )

    if ( ! wp_verify_nonce( $_POST['pts-nonce-select'], 'post-type-selector' ) )

    if ( ! current_user_can( 'edit_post', $post_id ) )

    if ( $_POST['pts_post_type'] == $post->post_type )

    if ( ! $new_post_type_object = get_post_type_object( $_POST['pts_post_type'] ) )

    if ( ! current_user_can( $new_post_type_object->cap->publish_posts ) )

    if($post->post_type == 'revision')

    set_post_type( $post_id, $new_post_type_object->name );
add_action( 'save_post', 'pts_save_post', 10, 2 );
  • Bueno. This looks like it is working. Thank you!! (See my answer for instructions on fixing a database that has already been affected.) Mar 30, 2012 at 13:47

As of now the Post Type Switcher plugin is causing this problem. (See this forum post.)

After deactivating the plugin, I ran the following to update the database:

UPDATE `wp_posts` set `post_type` = "revision"
  WHERE (`post_name` LIKE "%revision%" OR `post_name` LIKE "%autosave%")
  AND `post_status` = "inherit"
  AND `post_parent` != 0
  AND `post_type` != "revision"

WARNING: Backup up your database first! :)

WARNING: If you're on a WordPress network install be sure to change wp_posts to wp_XX_posts (where "XX" is the id of your site) and run it for each one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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