Last active
June 7, 2018 22:07
-
-
Save tawanorg/6f2e520109577338ae45 to your computer and use it in GitHub Desktop.
use $wpdb Insert Multiple Records Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setup arrays for Actual Values, and Placeholders | |
$values = array(); | |
$place_holders = array(); | |
// Then loop through the the values you're looking to add, and insert them in the appropriate arrays: | |
foreach($_POST as $key => $value) | |
{ | |
array_push($values, $value, $order_id); | |
$place_holders[] = "('%d', '%d')" /* In my case, i know they will always be integers */ | |
} | |
// Then add these bits to the initial query: | |
$query .= implode(', ', $place_holders); | |
// @author @mrtw | |
// check true and false in querying | |
if($wpdb->query( $wpdb->prepare("$query ", $values))); | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
CREDIT : http://stackoverflow.com/a/12374838 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment