Displaying checked ACF items in loop

It seems I was a little tired yesterday and didn’t quite think this through all the way, but having looked at it with fresh eyes today I’ve figured out what your issue is. Two important factors at play here:

  1. ACF checkbox fields save data as an array (I think that’s what it’s called) so if you just added the tag <Field services /> to one of your profile posts, you’d see that the data was saved in a format that looks like ["Checkbox 1 value","Checkbox 3 value","Checkbox 8 value"] if your first, third, and eighth ACF checkboxes were checked on that post.
  2. The acf_checkbox=field_name query parameter is designed to allow you to loop through all the checked items on a single post. It’s not a query parameter that can be used to filter another query, as you’ve done in your markup.

You might want to read this forum post by Eliot to better understand the different ways of choosing what posts you want to display in your query. Since ACF checkbox custom field values are stored as an array and not a simple string, you can’t use custom_field to filter your query, so instead you’ll want to use the field attribute documented here.

This means that you’ll probably want to use attributes like this to filter your query: field=services field_compare=in field_value=surv.

1 Like