• Resolved hp3

    (@hp3)


    Can someone provide an example of using the IN operator with meta_query?

    I am trying to find posts which have one of 3 possible terms stored in a meta field. So, I want to find all posts that have term1,term2 or term3 stored in a specific meta field.

    I’ve tried

    'meta_query' => array(
    		     array(
    			'key' => 'meta_field_name',
    			'compare' => "IN('term1','term2','term3')"
    		     )
    	        ),

    But I end up with posts that have terms other than these 3, like ‘term4’, in the meta field.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think this is what you want:

    'meta_query' => array(
       array(
           'key' => 'meta_field_name',
           'compare' => 'IN',
           'value' => array('term1','term2','term3')
       )
    ),
    Thread Starter hp3

    (@hp3)

    thanks, that was the solution.

    Thread Starter hp3

    (@hp3)

    thanks for your help. that was the solution.

    If your problem has been solved, please use the dropdown on the right to mark this topic ‘Resolved’ so that anyone else with this question can see that there is a solution.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_query and IN operator’ is closed to new replies.