Hi,
I created a system to book rooms with toolset and where users can log in and pay online. The system has also to generate a receipt when user pays and the receipt number should be sequential starting from 1. To do so, I created this function:
function get_reference_nb_func1($typeTransaction) {//to be called in code
$ref = get_post_meta( 643, 'wpcf-referencenb', true );
$ref+=1;
update_post_meta(643, 'wpcf-referencenb', $ref);
return $ref;
}
Whenever I generate a receipt, I call this function to increment the variable wpcf-referencenb. It works most of the time, however, when I noticed sometimes gaps in the numbers sequence, I guess because of the concurrency. Do you have a better idea to implement this with toolset?
Your implementation is simple, but I'm not sure if there is something in your code elsewhere that would account for the occasional gaps.
The code is rudimentary, it gets the current value, increments it, and updates the stored value.
To me the problem with site visitors triggering this more-or-less simultaneously is that you could end up with duplicates rather than gaps, e.g. one visitor triggers this code and gets a value of 17, increments it to 18, but before they update the stored value another user triggers the same code which gets the existing stored value of 17, increments it, and both update the stored value to 18.
I can't see a scenario where a gap would occur, but, as I say, you may have some code elsewhere that accounts for it.
In any case, it is not a Toolset thing as such, I'm not sure that I can help you much further with it.