Wordpress filter by checkbox ACF field not working

admin

Administrator
Staff member
I'm trying to allow users to filter wordpress posts based on the values in an ACF checkbox field. So I have an options form:

Code:
<form name="SelectDigit" method="post">
        <select name="Digit">
            <option></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>                
        </select>
        <input type="submit"  value="Filter posts" />           
</form>

Which passes through a value:

Code:
   <?php $SelectedDigit  = $_POST["Digit"]; ?>

To my WP Query:


Code:
        if (isset($_POST["Digit"]) && !empty($_POST["Digit"])){


            //args

            $args = array(
            'numberposts'   => -1,
            'post_type'     => 'post',
            'meta_key' => 'checkbox',
            'meta_value' => $SelectedDigit,
            'compare' => 'IN',
            );


        $wp_query = new WP_Query($args);


    if( $wp_query->have_posts() ): 

     while( $wp_query->have_posts() ) : $wp_query->the_post(); 

      the_field('title'); 

     endwhile;
    endif;
    }?>

It doesn't work. However, I also have a radio button ACF field. When I change my args to:

Code:
        $args = array(
        'numberposts'   => -1,
        'post_type'     => 'post',
        'meta_key' => 'radio',
        'meta_value' => $SelectedDigit,
        'compare' => '=',
        );

It works fine for radio fields. What's the difference? How can I get it work on checkboxes? I've asked ACF support, but they're not being very helpful... Thanks!