You can’t use LIKE
to compare arrays. LIKE
is used to check if a string matches, or partially matches, a value in the database.
IN
is used to check if a value in the database is in a given set of values.
They are not interchangeable.
The correct comparison to use in your case depends entirely on what data you’re using, and what you’re trying to do, which is not clear from your question, or comments. But here’s some pointers:
- If you want to match a partial string, use
LIKE
. - If you want to match a value in an array of values, use
IN
. - If you want to match values between an array of two given values in, use
BETWEEN
. - If you want to match an exact string or number, use
=
. - If you want to match multiple partial strings in an array, you need to split that array into separate
LIKE
queries for each item in the array.
The “strange” query you are seeing is $wpdb
‘escaping’ the %
placeholders used in LIKE
queries. This is expected, and is part of a security feature added in 4.8.3. You can learn more at this answer.