Filtering posts by ACF meta query

I am trying to filter posts by a meta_query, based on a post field.
The field type is checkbox.

The field configuration is:

acf_add_local_field_group(array (
‘key’ => ‘group_5a579h8fs9a98a’,
‘title’ => ‘Bingo Options’,
‘fields’ => array (
array (
‘layout’ => ‘vertical’,
‘choices’ => array (
‘bingo’ => ‘This is Bingo promotion’,
),
‘default_value’ => array (
),
‘allow_custom’ => 0,
‘save_custom’ => 0,
‘toggle’ => 0,
‘return_format’ => ‘value’,
‘key’ => ‘field_59jafj0s5c9ea’,
‘name’ => ‘is_bingo_promotion’,
‘type’ => ‘checkbox’,
‘instructions’ => ‘Select this if you want this promotion to be shown on bingo page’,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
),
),
‘location’ => array (
array (
array (
‘param’ => ‘post_type’,
‘operator’ => ‘==’,
‘value’ => ‘promotions’,
),
),
),
‘menu_order’ => 0,
‘position’ => ‘normal’,
‘style’ => ‘default’,
‘label_placement’ => ‘top’,
‘instruction_placement’ => ‘label’,
‘hide_on_screen’ => ”,
‘active’ => 1,
‘description’ => ”,
));

So, inside the WP I get a checkbox. and when it is checked, i want this query to get it for me:

$args = array(
‘post_type’ => ‘promotions’,
‘posts_per_page’ =>-1,
‘order’ => ‘DESC’,
‘meta_query’ => array (
array (
‘key’ => ‘is_bingo_promotion’,
‘value’ => ‘bingo’,
‘compare’ => ‘LIKE’
)
)
);

WP_Query( $args );

But this query doesn’t filter the posts. It gets all of them.
What am i doing wrong with the meta_query?

P.S.
I know that the field type should have been true_false instead, but this is due to legacy.

Read more here:: Filtering posts by ACF meta query

Leave a Reply

Your email address will not be published. Required fields are marked *