Home › Forums › ACF PRO › Auto-incrementing numeric field. › Reply To: Auto-incrementing numeric field.
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.