Support

Account

Home Forums Backend Issues (wp-admin) meta query using ACF checkbox fetch posts with multiple checkbox values

Unread

meta query using ACF checkbox fetch posts with multiple checkbox values

  •     $args = array(
                'posts_per_page' => -1,
                'post_type'  => 'products',
                'meta_query' => array(
                  array(
                    'key'     => 'colors',
                    'value'   => serialize(array('red', 'green')), 
                    'compare' => 'IN',
                  ),
                ),
              );
        
        <?php
              $the_query = new WP_Query($args);
              if ($the_query->have_posts()) {
                while ($the_query->have_posts()) : $the_query->the_post(); ?>
                  <?php echo get_the_title(); ?><br>
                  <?php $counter++; ?>
              <?php endwhile;
                wp_reset_postdata();
              } else {
                /** no posts found **/
              } ?>

    I have a query like the above, it works fine and it fetches posts with the exact value of checkbox with red and green. however, when a posts have checkbox value of red and green, but the query only wants green, the post with checkbox value red and green is not fetched. is there anyway to achieve that?

    this is a sample meta value from a post:

    a:2:{i:0;s:3:”red”;i:1;s:5:”green”;}

    if I’m only looking for green, this post is not fetched. the checkbox array value of the post is greater than the meta query parameter.
    thanks in advance.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.