I apologize beforehand for any confusion, I'm just 2 days with WP.
So, I use Advanced Custom Fields to add formatable custom fields to posts of partucular type.
One of fields is checkboxes with multiple choice with name spec
.
Now I want to get all posts where spec
has one or more values checked.
For example: choices for this field are {"choice1","choice2",choice3","choice4","choice5"} In some post I selected "choice2" and "choice3" and saved these posts.
if I print spec
in loop
print_r( get_post_meta($post->ID,'spec',true));
it can looks like:
Array
(
[0] => choice2
[1] => choice3
)
Now I want to get all posts where "choice2" or "choice3" are selected (or may be only choice2
or only choice3
):
query_posts(
array(
'cat' => 6,
'posts_per_page'=>-1,
'meta_query' => array(
array(
'key' => 'spec'
'value' => array('choice2','choice3'),
'compare' => 'IN'
)
)
)
);
But that not works. As I understand the real condition will be WHERE spec IN 'choice2'
, where choice is array. But I need opposite condition - something like in_array('choice2',spec) || in_array('choice3',spec)
. May be there is some HAS
value for compare
?
So my question - how can I get all the posts where meta field with multiple choice has several values checked?