Multiple rows insert in WordPress

----------------------------------------------------
$items         = [];
$values        = [];
$place_holders = [];
$query         = "INSERT INTO {$wpdb->prefix}table_name (col1, col2) VALUES ";
foreach ( $your_data_array_here as $key => $val ) {
    array_push( $values, $col1_value );
    array_push( $values, $col2_value );
    $place_holders[] = "('%d', '%d')";
}

$query .= implode( ', ', $place_holders );
$wpdb->query( $wpdb->prepare( "$query ", $values ) );

------------------------------------------------------
//set your key and data as per your needs.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>