Building a plugin in one of my not to strong languages, PHP.
In this plugin i need a function that stores a ID for me and increase it with given value on every execution. With this code i could achieve: for every execution increase given value with +1
$wpdb->query("UPDATE `wp_selector` SET `name`= name+1 WHERE 1");
Result upon every execution: 1, 2, 3, 4, 5..etc
Did try to use same method where my initial value was something like ‘ABC000001’ trying to achieve ABC000001, ABC000002, …ABC056211
Result: 1,2,3..
When Plugin activates i create table and put my initial value like ‘ABC000001’ in ‘name’
How can i increase the value with +1 and keep the structure of my value, So it will go to ‘ABC000001’and continue it increment so it finally would end up like ‘ABC999999’and not ‘ABC00000999999’
Storing custom global data is what the wp_options table is for and WordPress has some functions to help you with this. You could go a few different ways with this depending on exactly how you want it to work but I would do something like this…
this function stores a number in the options table, adds 1 to the number every time and returns a formatted string by prepending the number stored with ‘ABC’ and using str_pad() to make sure the number string is 6 digits long.
Now everytime you want to generate a new ID you can just use…
Hope that is the answer you’re looking for.
Regards
Dan