1

You can use a variety of different comparison operators in meta queries, among which are 'LIKE', 'NOT LIKE', 'IN', and 'NOT IN'.

What is the difference in use between LIKE and IN?

Here's the relevant section of the WP Query Codex page:

meta_query (array) - Custom field parameters (3.1)

  • key (string) - Custom field key.
  • value (string|array) - Custom field value (Note: Array support is limited to a compare value of 'IN', 'NOT IN', 'BETWEEN', or 'NOT BETWEEN')
  • compare (string) - Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. Default value is '='.
  • type (string) - Custom field type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'. Default value is 'CHAR'.

2

Meta queries are essentially wrapper for ease of setup, but end results is part of SQL query to run on MySQL database.

These operators are those of MySQL, see in documentation:

  • So IN would accept an array? – supertrue Jan 18 '12 at 15:44
  • @supertrue from quick look at code it should and IN seems to be even automatically used instead of = in such case. – Rarst Jan 18 '12 at 19:29
0

Mostly used two operates in metaa queries 1. like 2. in 1 - [LIKE (performs pattern matching) or not ] 2 - [IN() (checks if value is in set or not ]

array(
    'key' => 'practice_area',
    'value' => '"'.$post->ID.'"',
    'compare' => 'LIKE',
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.