You can get the last inserted ID from $wpdb
with the insert_id
property:
$wpdb->insert( ... );
$couponId = $wpdb->insert_id
Related Posts:
- Using wpdb to connect to a separate database
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- Inserting Post Meta From SQL
- Why does dbDelta() not catch MysqlErrors?
- What causes the “max_user_connections” warning on WordPress frontend?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Database slowdown after update to 3.4.1
- wpdb_prepare with multiple or condition
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Advanced SELECT query with condtional statements
- Redirecting to old domain after migration website
- Create table from array with prepare
- WordPress running SQL query to update database from form
- Have working sql query… trying to adjust it to use $wpdb
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- Query Column of Specific ID from Database Table
- How to create more than one new wpdb object?
- How to connect and insert data in database of wordpress?
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- “BS_” rows in postmeta table
- Where is the HTML-handler part in the wpdb class?
- WordPress Database Query works in phpMyAdmin but not in the code
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- How To connect to the same WordPress database with different database user
- using same mysql user with many databases
- Uploading to WordPress Database
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- MySQL SELECT increment counter
- Detecting errors generated by $wpdb->get_results()
- wpdb update add current timestamp not working
- WordPress Database lost auto increment
- Restoring WordPress posts from database only
- Slow wp_term_relationships query
- How to use “TRUNCATE TABLE” MySQL statement?
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- Export wordpress table to excel
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- What are conventions about the schema of the $table_prefix
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- Is deleting orphaned wp_options entries safe?
- How to solve slow WordPress site caused by attachment_metadata
- Delete all post meta except featured image
- WooCommerce – Query for ordered products
- Large database causes slow load
- Safe way to find last inserted id in a table?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- How to insert data into MySQL database from the form created in WordPress site
- Select Multiple meta_value from WP DB; Single Query
- Multiple postmeta with same name for one post in wp_postmeta table
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- Is it possible to split database tables using HyperDB?
- What happens if I overwrite the current wp_options table with a backup from a week ago?
- Modify Database in Multi-Site wp_usermeta table
- $wpdb doesn’t like to store arrays
- Handling large N data in WordPress
- How to Mirror WordPress database from Remote server to Local server
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- Update results, Before deleting the related category [closed]
- A MySQL DB within a MySQL DB
- How do I query wp_options for expired transient pairs with MySQL commands?
- Is there a way to recover the table wp_term_relationships?
- Trouble Migrating all data blog from WordPress.com to WordPress.org
- How Can I Put Meta_Compare in the Database-Query?
- How do I convert a MySQL database from utf8mb4 to utf8 encoding?
- $wpdb error (Call to a member function insert() on a non-object)
- Is it important to have integers inserted using %d rather than %s?
- Why this query is not showing any result on wordpresss home page?
- I can’t update my data through $wpdb
- How to get a list of WordPress default database tables?
- Using $wpdb | checking entered email against existing emails in db
- how to encyrpt DB_PASSWORD in wp-config
- Optimizing function that automatically creates internal links based on post title string
- How to get product order by two custom taxonomy in wordpress
- Get results from wordpress data custom table
- Outputting query results
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- Creating and Using Tables in the WordPress Database
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to insert a value to decimal type field using wpdb->prepare?
- How to import products in host instead of database on wordpress?
- I would like some help wth an SQL query to link posts with categories
- Correct and secure way to access a custom SQL database in a custom PHP template file
- Merging development site with live site
- The MySQL Connection could not be established., before it was joomla but i have change it into worpress
- Missing latest posts and options after DB migration via phpMyAdmin
- live site do not update after importing sql database
- How do i get value from wp_postmeta?
- How can I retrieve data from alternate database using wpdb class?
- “MySQL server has gone away” since update to 3.8
- featured image not showing up with mysql_connect
- Print output of Table Creation
- How to delete field using WPDB?
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- WordPress database connection failed, while mysql client is working [closed]