[wp-hackers] WP 3.5.2/multisite: How to use NOT IN in $wpdb->prepare()?
Micky Hulse
mickyhulse.lists at gmail.com
Tue Jul 16 18:27:43 UTC 2013
On Tue, Jul 16, 2013 at 5:52 AM, Andrew Nacin <wp at andrewnacin.com> wrote:
> If your query doesn't have a placeholder, then don't use prepare. As in:
> $rows = $wpdb->get_results($wpdb->prepare("SELECT blog_id FROM
> $wpdb->blogs WHERE blog_id NOT IN ($ignore) AND public = '1' AND archived =
> '0' AND mature = '0' AND spam = '0' AND deleted = '0'", $ignore),
> ARRAY_A)
On Tue, Jul 16, 2013 at 10:55 AM, Micky Hulse
<mickyhulse.lists at gmail.com> wrote:
> Andrew, thanks for pointing me towards get_results() (and for the
> additional details and example code).
For some reason, in the example code above, my eyes skimmed over the
"prepare()" bit .. When I read "don't use prepare", I saw
"get_results()" and assumed that I could use that without using
prepare(). Lol, it's still early and the coffee has yet to kick in. :D
Andrew, in your example above, I see that you have $ignore in both
spots. I assume you meant to delete the $ignore argument from the
prepare()? Or, to clarify, you must be saying to leave it there as an
unused argument (otherwise, prepare will throw that PHP notice)? Sorry
for me being so dense.
Thanks again Andrew and all!
Cheers,
M
More information about the wp-hackers
mailing list