Skip to content

Instantly share code, notes, and snippets.

@felipelavinz
Created October 18, 2012 19:41
Show Gist options
  • Select an option

  • Save felipelavinz/3914346 to your computer and use it in GitHub Desktop.

Select an option

Save felipelavinz/3914346 to your computer and use it in GitHub Desktop.
sanitize data on "IN" clauses with wpdb
<?php
$menu_items = array();
foreach ( $menus[$menu] as $item ) $menu_items[] = $item['id'];
$placeholders = implode(', ', array_fill(0, count($menu_items), '%s'));
$query = "SELECT post_name, ID, post_title FROM $wpdb->posts WHERE post_name IN($placeholders)";
$results = $wpdb->get_results( $wpdb->prepare($query, $menu_items), OBJECT_K );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment