Post loop with 'acf_true_false' condition

Hi there,

This loop returns all gallery posts instead of just the ones with the ACF true/false field set to ‘true’. I could not find an example of this loop, so maybe I have the syntax wrong. :thinking:

<Loop type="gallery" acf_true_false="featured_gallery" custom_field_compare="equal" custom_field_value="true">

Thanks,
Phil.

Hi Phil,

In this case, you probably need to do something like

<Loop type=gallery>
  <If acf_true_false=featured_gallery>
    // Fields here
  </If>
</Loop>

I am not sure if you can do it with a comparison, as booleans are not listed as one of the available field types. I might be wrong though.

You’d want to use custom_field="featured_gallery" instead of acf_true_false="featured_gallery" since acf_true_false is not a valid query parameter that can be used on post loops.

If ever that still doesn’t work, you might want to test the actual output value of your featured_gallery field to see what it actually contains. There’s a chance you might need to use a different approach to filter your loop such as the one @Birkeholm suggested.

Thanks all! The main issue was that the front-end posting form was storing the values as yes/no instead of 1/0. :slight_smile:

This loop works:
<Loop type="gallery" custom_field="featured_gallery" custom_field_compare="equal" custom_field_value="1">

1 Like