Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Last active August 29, 2015 14:28
Show Gist options
  • Save khoand0000/b9c348db1afdfaa2295a to your computer and use it in GitHub Desktop.
Save khoand0000/b9c348db1afdfaa2295a to your computer and use it in GitHub Desktop.
Use $wpdb->prepare with parameter is array
// ref: http://wordpress.stackexchange.com/questions/110982/how-to-modify-this-wpdb-query-to-accept-an-array-of-post-statuses
// escape the values
// $filter is array of string
$filter = array_map( 'esc_sql', (array) $filter );
$filter = "'" . implode( "','", $filter ) . "'";
$rows = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM language_table
WHERE language_code=%s AND id IN (" . $filter . ") ORDER BY id",
$language_code
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment