When our users submit a form (Contact 7), I want to get the next available Auto-Increment number (order-post-ID) and insert this into one of the fields. This is sent along with the form in order to create a link to the Flamingo Inbound Message post.
As of now, it works but is not entirely accurate. Every so often, the number sent is one lower than the actual post ID. For example, one order can be accessed through the dashboard:
/wp-admin/admin.php?page=flamingo_inbound&post=8601
However, the order-post-ID sent with this was 8600. I've tried disabling the buttons and auto-saving to ensure that multiple submissions are not occurring; am I missing something obvious?
My code is below:
function getLastID() {
global $wpdb;
$next = $wpdb->get_var($wpdb->prepare(
"
SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'wordpressDB'
AND TABLE_NAME = 'wp_posts'
"
), 0, 0 );
echo $next;
$wpdb->flush();
exit();
}
Thank you.
wp_posts
table for ID = 8600 ?