i have an array of meta values of an unknown length and i'm trying to query for posts that contain them.

The type of meta value is the checkbox type. So in ACF this is a list of 10 different checkboxes you can check. I take the checks made in HTML and am trying to query for posts with them when someone presses search.

here's what I have

$query = new WP_Query( array(
            'posts_per_page' => 12,
            'post_type' => 'post',
            'post_status' => 'publish',
            'meta_query' => array(
                'key' => 'category',
                'value' => $checkboxes,
                'compare' => 'In'
        ) );

the name of ACF checkboxes field is category, i'm trying to check if anything from category is in my checkboxes array. but nothing shows up>

  • How is ACF storing that data, as separate rows, or a serialized array? Also- show us the code that sets $checkboxes. – Milo Nov 2 '18 at 1:25
  • @Milo i think as separate rows, i found this in the database: "category | school" then "_category | field_5b91a30de9f3e" both with the same post ID where school is one of checkboxes in category – Tintinabulator Zea Nov 2 '18 at 3:18
  • @milo it's actually serialized i think. But I could get around this with the 'like' compare i think? However how do i make meta_queries programatically? since checked boxes is of an unknown length – Tintinabulator Zea Nov 2 '18 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.