Making posts permalinks consistent numbers

I don’t really have the time or will to write and debug the code to make this work, but I can point you down a path to how you might make this work. A word of warning: it’s certainly not simple.

  1. You have to save the current number somewhere so you can retrieve and increment it every time a post is added, I would do this in an option.

  2. You have to associate the number to each post via a custom field so they can be queried. This would be done via the save_post action hook. Prefix the custom field key with an underscore to hide it from the admin UI.

  3. You have to insert this number into the post permalink when WordPress generates it, this is done via the post_link filter (sadly there is no codex example, but you can find some examples on this site, I’ve written a few myself).

  4. When incoming requests are received, you need a rewrite rule to convert it into query vars. I would add a custom query var that you set in your rewrite rule so when the query is parsed you can look for this query var and rebuild the query (example of adding a query var or add_rewrite_tag). You may need to set a dummy post id or something to get past the parse_request and parse_query stages.

  5. When the actual SQL query is generated, you have to change the query to load the post based on the value of the custom field matching your custom query var, you can do this on the pre_get_posts action. See WP_Query for info on setting query vars for a custom field query.