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
- Delete data from database using row action
- Show dynamic list of products from custom api of another database under same host
- WPDB: Update table
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- Issue running db create table query from static method
- $wpdb->prepare with LIKE and sprintf
- Prevent WordPress automatically processing certain URL queries
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- $wpdb->query can’t insert data
- Custom WordPress Table wpdb
- Why in this archive page that call query_posts() function show only the last 10 posts?
- insert query on a custom table using ajax with jQuery plugin Jeditable
- How to optimize multiple insert into wordpress database
- 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?
- $wpdb->update() always need a second try
- How best to handle database version dependence (from $wp_db_version)
- WP: Search and replace in DB programmatically
- Using AND and bracket grouping in SQL not working
- Taxonomy archive page listing terms instead of posts
- Two different wordpress sites – same server and IP address. Gaining Access to database 1 of 2
- Connecting to a different database
- Query Column of Specific ID from Database Table
- Plugin Development: Storing and Manipulating Data That Fits JSON in Database
- Data inserted by wpdb insert is different than data pressnt in database.
- Proper Prepare Statement for ALTER TABLE and using AFTER
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- $wpdb->prepare is not working like mysql_real_escape_string
- Brainstorm – Slow Query from Plugin Need to Speed It Up
- 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?
- Save temporary registration data
- $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
- How to relate the Category to user?
- dbdelta failing with error: “WordPress database error Table ‘wp_2_myPlugin’ already exists
- Why doesn’t my Table get created?
- Downloading File via headers doesnt work
- Load specific page when a custom URL is hit
- How to display specific data from a custom table to logged in users with a custom role
- $wpbd->insert_id is returning null
- Error code when migrate
- 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?
- Insert NULL value using prepare()
- Why User_login key doesn’t work with wp_update_user()
- How to grab data after wp user search is complete
- WP_Query not ordering correctly
- How to store sensitive user data (passwords)
- 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
- WordPress Query doesn’t return the correct value
- WordPress Fatal error: Uncaught Error: Call to undefined function dbDelta()
- WordPress Database Query works in phpMyAdmin but not in the code
- woocommerce add a new bulk action in the bulk actions dropdown in the orders list
- Use admin-post to submit form data to external database
- User avatar-ACF fields
- 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
- Insert Data into Database
- How to store in the database directly the translation?
- 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
- pull data from wordpress database
- Dedicated server and WPDB Class : huge slow-down of the website
- How to implement pagination into a wpdb->result query?
- How to CRUD from wordpress database in wordpress theme?
- Should I Use only wpdb Class to Write Custom Queries?
- Array/List Edit in Backend
- Ajax not working to insert, query and result data
- 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
- How to filter get_adjacent_post()?
- Associating special meaning with user id 0
- $wpdb how can i save my postmeta table before querying it
- Pulling values from a sepcific row in table
- What method should I use to store my plugin data (multi level menus with options on each item)