Skip to content

Instantly share code, notes, and snippets.

@tawanorg
Last active June 7, 2018 22:07
Show Gist options
  • Save tawanorg/6f2e520109577338ae45 to your computer and use it in GitHub Desktop.
Save tawanorg/6f2e520109577338ae45 to your computer and use it in GitHub Desktop.
use $wpdb Insert Multiple Records Wordpress
// 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