Your query works perfectly fine for me, have you considered that the query might simply not be finding any matches?
I get 8 results from your query on my test install..
NOTE: If you only want the IDs, use get_col
…
$wpdb->get_col( "SELECT ID FROM $wpdb->posts where instr(post_content, ']') > 0");
This way you’ll get a flat array of IDs, instead of an array of objects..
Thread Starter
kc11
(@kc11)
Thanks Mark,
I had originally used :
$start = '[';
$postID = $wpdb->get_results( "SELECT ID FROM $wpdb->posts where instr(post_content, $start) > 0");
which does not work. However,
$postID = $wpdb->get_results( "SELECT ID FROM $wpdb->posts where instr(post_content, '[') > 0");
does work.
KC
Ah i see the problem, when you use the sting method, you actually lose the single quotes you need around the value inside the query..
The instr call ends up like this..
instr(post_content, [ )
You could use the original method, you just need to include the single quotes inside the string..
$start = "'['";
This way the single quotes get passed along into to the SQL statement..
🙂