Skip to content

Instantly share code, notes, and snippets.

@faishal
Last active April 11, 2016 13:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faishal/c4306ae7267fff976465 to your computer and use it in GitHub Desktop.
Save faishal/c4306ae7267fff976465 to your computer and use it in GitHub Desktop.
WPDB In Query Prepare
<?php
global $wpdb;
if ( is_array( $ids ) ) {
$in_str_arr = array_fill( 0, count( $ids ), '%d' );
$in_str = join( ',', $in_str_arr );
$form_id_where = $wpdb->prepare( "ID IN ($in_str)", $ids );
} else {
$form_id_where = $ids> 0 ? $wpdb->prepare( 'ID=%d', $ids ) : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment