WordPress.org

Ready to get started?Download WordPress

Forums

How to workaround autosave and revisions (3 posts)

  1. pete_398
    Member
    Posted 3 years ago #

    I see a number of people are frustrated that WordPress can't just have post id's sequential. Like first post - 1, second post 2, etc,etc. Seems there are many methods to 'force' it to happen that way. Here is what I found, after needing to convert an XOOPS site that had WP in it, and the post Id's weren't sequential.

    1. Install plugins wordpress-importer and wp-optimize.

    2. Export your posts in WP format, so you get to know what the XML format looks like.

    3. When I need to add a post, I simply ......

    (a) Edit the XML file, content is not important, as once the post is imported, the post ID is 'set'.
    (b) Run wp-optimize, so that all the 'garbage' is removed.
    (c) Import the XML file, which has the next sequential post ID specified, within it.

    This works okay for me, because when I reloaded/imported all the posts from XOOPS, and 'forced' the post ID to be sequential, the last post id was the same number as the number of rows in the posts table.

    The XML file to be imported each time is simply modified, to specify the next post ID. As long as you run wp-optimize prior to the import (wordpress-importer plugin), then the next post ID will be what you have specified in the XML file.

    I notice that even if I login to WP admin, there is a row added with 'auto draft' in it, you can get rid of this with wp-optimize. The ID number for that auto draft was much higher than the value set in the table "wp-usermeta", row "wp_dashboard_quick_press_last_post_id" , which did have a low value before going into the dashboard, and as soon as the auto draft is added, the value is adjusted to the autodraft ID value.

    WordPress is obviously getting the next ID for the posts table, from the table "wp-options", rather than doing a simple check on the cardinality of the posts table, and ensuring the last post id is not a higher value.

    It's not rocket science, but WP developers, why not simply have the posts table containing posts with all sequential ID's, and let the user decide if they want 'autosave', 'drafts', or 'revisions', etc ??

    If the user wants those "features", simply 'park' them in a table called 'drafts' or similar. The db design could certainly do with some improvements.

  2. pete_398
    Member
    Posted 3 years ago #

    WordPress is obviously getting the next ID for the posts table, from the table "wp-options", rather than doing a simple check on the cardinality of the posts table, and ensuring the last post id is not a higher value.

    Seems after a bit of researching, that this is not correct. WP appears to be getting the value from the posts table. Here is a proven method (no guarantees though, remember, backup first), ..

    1. Obtain the highest ID value for the posts table

    This can be done in MySQL, by the function 'SELECT LAST_INSERT_ID(); , however it seems that function needs to be run on an INSERT for the value to be present. The easiest way is to view all the rows, and sort to post_id order, thereby displaying the highest value.

    In this example, it was 32.

    2. Modify wp_posts table to that value PLUS one

    ALTER TABLE wp_posts AUTO_INCREMENT = 33;

    This seemed not to work in phpMyAdin, it gave an error, yet the value was set to 33, on inspection. Apparently that command works fine in MySQL though.

    3. Update table wp_usermeta, row wp_usermeta, to the same value of 32.

    UPDATE database_name.wp_usermeta SET meta_value = '32' WHERE wp_usermeta.umeta_id =16;

    (Your 'umeta_id' value may be different ??). The column 'meta_key' is 'wp_dashboard_quick_press_last_post_id'. )

    This last step simply sets the last post id to 32, in order to accomodate a quick press.

  3. pete_398
    Member
    Posted 3 years ago #

    Hmm, .. or the 'simple' method, just use the XML file with the post ID number hard coded in it, and you will be able to specify what post ID you want.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.