As described here:
If you insert multiple rows using a single INSERT statement,
LAST_INSERT_ID() returns the value generated for the first inserted
row only. The reason for this is to make it possible to reproduce
easily the same INSERT statement against some other server.
So if you need every inserted ID you should use single $wpdb->insert
commands, then you have the ID available for each with $wpdb->insert_id
. Docs here: https://codex.wordpress.org/Function_Reference/wpdb_Class#INSERT_row
If you insert many rows with a single query you can’t get all the inserted ID’s, unless you e.g. wanted to re-query for them if you are sure you can identify those rows uniquely.
Related Posts:
- Is it mandatory to use $wpdb->prefix in custom tables
- WordPress and multithreading
- Actions or filters fired when data is saved in a custom table
- Custom Plugin Database relations
- Activation hook not creating table
- Get a custom table to an array
- How to create database table, add data, update and delete using wpdb via plugins?
- Using WPDB to output raw XML fails because of wp-blog-header.php
- wpdb->prepare and mysql UPDATE – how is it done?
- $wpdb->update Issue
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- bindParam? WordPress 4.9.5 SQL LIKE statement %s and %LIKE%
- Update database record in plugin
- WordPress plugin tables become corrupt
- Can I log the searches that are returning 404 in the DB?
- multiple record insert creating many duplicate records
- Post meta vs separate database tables
- get_results using wpdb
- Using query_vars filter
- Using a database view = evil incarnate?
- Check for success of $wpdb->update() correctly
- Is their any way to Extend WPDB class and Overwrite the Default Query Function
- Export wordpress table to excel
- How is the data stored in the database?
- $wpdb->insert is changing a value
- Retrieving custom fields with $wpdb->get_results
- Sample — test — data for large WordPress install
- Is there any reason only 1 (my) IP would be added to this table using $wpdn->insert?
- why creating tables using $wpdb is not being executed while installing plugins?
- How to use mysql IN statement with wpdb update method?
- How to store data for posts/pages built with drag-n-drop builder?
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Creating table with plugin is not working
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- dbDelta() Error – Incorrect index name ” for query ALTER TABLE
- Update/insert only a column of database table
- How to Create database table when Plugin installed/activated, and delete database when Plugin deleted
- Where to store the name of a custom table?
- include wp-blog-header not working on MAMP
- WordPress database error for query INSERT INTO
- How to connect to AWS RDS external database (not for the core WordPress db)
- SQL query for custom taxonomy slugs
- Issue regarding $wpdb->prepare()
- Select two sums with single get_var statement
- Error on inserting a form value to database
- Strange issue saving custom field data for a WooCommerce order
- how to search users by ajax live search
- Form doesnt save to database
- Adding custom end points, No error line
- Intermittent database errors when accessing WordPress database
- Updating Woocommerce Settings API when WordPress Settings API saved and vise versa
- Storing data in wordpress database from ajax call from different website
- Is using custom table to suit business needs instead of transients a big hit to page load speed?
- $wpdb->replace: WHERE?
- Admin Posts List (edit.php) by post IDs
- plugin code is pulling information from database in one instance and not in other. What is wrong?
- Optimising a big WordPress site
- dbDelta SQL Query Not Working
- wp_get_post_terms Order by not working
- What is the best way to store a few fields?
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- $wpdb->query can’t insert data
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- Make Database query only when option is updated
- Can we intercept user_login and user_pass from a wp_login_form?
- Plugin Development: Storing and Manipulating Data That Fits JSON in Database
- Data inserted by wpdb insert is different than data pressnt in database.
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- How do I debug an error that a plugin is causing?
- $wpdb in php 5.5
- Update plugin settings option_name for big plugin update
- select a single val though a table in wordpress
- Plugin to create Posts and Forums then choose category and parent forum
- Checking for existing title in custom db query not working
- Why doesn’t my Table get created?
- How to display specific data from a custom table to logged in users with a custom role
- $wpbd->insert_id is returning null
- How to insert a value to decimal type field using wpdb->prepare?
- Does this archive template part look like its making too many calls to the db?
- How to grab data after wp user search is complete
- How to securely controlling data without keeping it in postmeta?
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- woocommerce add a new bulk action in the bulk actions dropdown in the orders list
- Save in my custom admin page and redirect to the saved object
- Relational / Associate tables using native WordPress functionality
- WordPress doesn’t create table on plugin activation
- How and when would I implement some code which would take data from one part of the Db and put it in another?
- WP Query Relations / Compare
- How to CRUD from wordpress database in wordpress theme?
- Should I Use only wpdb Class to Write Custom Queries?
- I can’t write in my DB using $wpdb->insert
- Why Worpdress doesn’t create table in database?
- Form and database, plugin development
- wpdb get_results() returns only 2 rows
- Pulling values from a sepcific row in table
- Nothing happens on WordPress Update command
- Running one-off cron jobs when WP_DISABLE_CRON is true: can I hit /wp-cron.php?
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- WordPress database error: [Table ‘bitnami_wordpress.questions’ doesn’t exist]