php - How to create db counter in wordpress -
let's i've got custom post type order
, custom field order number
, , let's these custom posts created on form submission.
what need increment order number
field automatically in safe way, numbers aren't duplicated.
the trivial solution: on form submission, find last order , use number + 1. in case when 2 users submit form @ same time, same order number.
i doing such things custom frameworks in past: lock db row update, increment number, release. safely increment number. require creating separate table counter , i'd prefer avoid that.
i didn't find ready in wp api.
i'm using wp 3.8 on mysql.
auto-increment functionality implemented long time ago in mysql, have specify id
of table auto_increment
.
however, if insert data on form submission , create custom post type, inserting data in wp_posts
table, done there, because table, posts stored in wordpress , already have id
set auto_increment
.
Comments
Post a Comment