Support » Developing with WordPress » Sequential Post ID per CPT

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You want sequential numbering that does not change if a post is deleted? But then the posts will no longer be sequential, there will be gaps in the numbering. You cannot have it both ways. Anyway, you could maintain the assigned number in post meta, managing the last number assigned as an option value that’s incremented with each new post. Or just query for the highest number, adding 1 for any new post.

    Each CPT would work almost as a customer receipt, hence why the number cannot change once assigned.

    How would i go about creating/assigning the number in post meta for a CPT?

    If I had to do this, I’d create a new table in the database that holds the post ID from WordPress along with an auto-incrementing field for the CPT ID. Then, when a new CPT item is added, add a new entry to this database table so that it can create the “unique” ID for that item. To make sure that these aren’t re-used, don’t do anything more then add the entry in, that way it won’t be updated or deleted any time later on.

    It is a bit of work to make happen but that’s really the only way to do it properly.

    Im relooking at this and still looking for a solution to implement, and happy to work with somebody to help get this integrated.

    This sounds similar to my needs:
    https://support.advancedcustomfields.com/forums/topic/how-can-we-create-an-auto-increment-id-on-custom-post-types-with-plugin/

    So ideally there would be an ACF field that holds the number, and it auto-increments for each new post in the defined Custom Post Type.

    Can anybody help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.