Support

Account

Home Forums General Issues ACF with FacetWP. Query works with radio but not checkboxes.

Helping

ACF with FacetWP. Query works with radio but not checkboxes.

  • My query works with radio but not checkboxes. I’m using a basic query format for facetWP to filter all posts with a type “Program” to see if the custom field drptest = “Educational”. It looks like this:

    <?php
    
    $my_acf_checkbox_field_array = get_field('drptest');
    
    return [
      "post_type" => [
        "programs"
      ],
      "post_status" => [
        "publish"
      ],
      "meta_query" => [
        [
          "key" => "drptest",
          "compare" => "IN",
          "type" => "CHAR",
          "value" => [
            "Educational"
          ]
        ]
      ],
      "orderby" => [
        "date" => "ASC"
      ],
      "posts_per_page" => "15"
    ];

    This works with a field as radio select… What would I have to do to make it function with checkboxes?

    Thanks in advance.

  • A checkbox field stores a serialized array in the DB.

    
    // to search for one of 2 values
    <code>meta_query</code> => array(
      'relation' => 'OR',
      array(
        'key' => 'drptest',
        'value' => 'Educational',
        'compare' => 'LIKE'
      ),
      array(
        'key' => 'drptest',
        'value' => 'some other value',
        'compare' => 'LIKE'
      )
    )
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.