Home Forums ACF PRO Auto-incrementing numeric field.


Auto-incrementing numeric field.

  • Is it possible to create a numeric field that automatically increases its number with each new entry? This field would be read-only, I tried to take an example from this, but it doesn’t seem to work.


    Could someone point me to an easier way?

  • Other than the suggestions in the topic you linked there is nothing new. There isn’t a way to create an auto-incrementing number fields without somehow storing the value of the last number created. As stated in the that other post, I would do this by having a WP options value to store this number. I would populate the field and increment that value.

    Another options would be to do this would be to query the _postmeta table directly to get the max value stored in the DB for that field.

    No matter what you do it will be prone to issues. For example, if you create two posts at the same time both could have the same number using either method. When using the options method you would have number skipped if you started creating a new post and updated the value before the post was saved and then decided not to save it.

    There really is no 100% reliable way of doing this. My suggestion would be to figure out why you need this and look for some other way do accomplish what you need.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.