Advanced Custom Fields Checkbox Query not Working
<p>For some websites I own, I would like my visitors to be able to filter on different Advanced Custom Fields on Wordpress Archive pages. To create such filters I used <a href="https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/" rel="nofollow">this tutorial</a>. </p>

<p>However, I can't seem to get the filter working the way I want. Here's my code for the archive page.</p>

<pre><code>function my_pre_get_posts( $query ) {

// bail early if is in admin
if( is_admin() ) {
    return;
}

// get meta query
$meta_query = $query-&gt;get('meta_query');

// loop over filters
foreach( $GLOBALS['my_query_filters'] as $key =&gt; $name ) {

    // continue if no values found in url
    if( empty($_GET[ $name ]) ) {           
        continue;
    }

    // get the values for this filter
    $value = explode(',', $_GET[ $name ]);

    // append meta query
$meta_query[] = array(
    'key'       =&gt; $name,
  'value'       =&gt; $value,
  'compare' =&gt; 'IN'
);       
}   

// update meta query
$query-&gt;set('meta_query', $meta_query);

//print_r($query);  

echo $GLOBALS['wp_query']-&gt;request;
</code></pre>

<p>Here's the SQL code it spits out on running:</p>

<pre><code>SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
INNER JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) 
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) 
WHERE 1 =1
AND (
wp_term_relationships.term_taxonomy_id
IN ( 2, 9, 11 )
)
AND (
(
wp_postmeta.meta_key =  'payment_method'
AND CAST( wp_postmeta.meta_value AS CHAR ) 
IN (
'Delta',  'Visa'
)
)
)
AND wp_posts.post_type =  'post'
AND (
wp_posts.post_status =  'publish'
OR wp_posts.post_status =  'private'
)
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC 
LIMIT 0 , 100
</code></pre>

<p>However, this SQL statement returns 0 results. I also ran this query:</p>

<pre><code>SELECT * 
FROM  `wp_postmeta` 
WHERE  `meta_key` =  'payment_method'
LIMIT 0 , 30
</code></pre>

<p>This does return results. Meta value for these results is something like:</p>

<pre><code>a:3:{i:0;s:5:"Delta";i:1;s:4:"Visa";i:2;s:11:"Visa(debit)";}
</code></pre>

<p>I guess there's something wrong with the generated query, but I have no idea what exactly. I hope someone here can help me out. Not sure if worth noting, but running the first bit of code also messes up my theme as it won't load the topmenu when for example ?payment_method=Delta,Visa is in the url.</p>

<p>Thanks in advance.</p>