[wp-hackers] $wpdb->prepare syntax problem

Ade Walker photofantaisie at gmail.com
Mon Oct 26 18:10:40 UTC 2009

Hi all,

I wonder if someone can point out what I'm doing wrong here.

$pages_selected is a string of comma separated ID numbers, eg "6,22,31,43"

This finds all the page IDs in the $pages_selected string =>

$pages_found = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
WHERE $wpdb->posts.ID IN( $pages_selected )" );

This doesn't =>

$pages_found = $wpdb->get_results(
        $wpdb->prepare( "SELECT ID,post_title FROM $wpdb->posts WHERE
$wpdb->posts.ID IN( %s )", $pages_selected )

It just finds the first page ID in the $pages_selected string.

I've searched high and low, but can't find out what I'm doing wrong. No
error in php error log either.

Any pointers gratefully received. :-)



More information about the wp-hackers mailing list