$wpdb->prepare()
doesn't actually fully support sprintf()
placeholders.
From the Codex:
The query parameter for prepare accepts sprintf()-like placeholders. The %s (string), %d (integer) and %f (float) formats are supported.
It's not entirely obvious from that but the argument swapping formats (e.g. %1$d
) are not supported (in any case you have the incorrect syntax: it should be %2$s
instead of %2s
)
global $wpdb;
$wpdb->prepare(
"SELECT * FROM location
WHERE name LIKE %s OR name LIKE %s",
'%'.$wpdb->esc_like('on'),
'%'.$wpdb->esc_like('on').'%'
), ARRAY_A);
I'm assuming 'on' might be replaced by a unknown value - otherwise $wpdb->prepare()
isn't necessary. On an unrelated note, the second condition in your SQL makes the first obsolete.