Comparing ACF Checkbox Values in a Loop
-
First off, I really love this plugin. I have been able to do a lot of really cool things with it.
I could really use some help on getting the following to work – here is the scenario:
I have certain products that only show up on related products based on the location of a property. I have a taxonomy called city that maintains a list of locations. I have an ACF checkbox field tied to that taxonomy. I can return the list of cities that a product can be offered on, and I can return the city in which a property resides. But when I try to compare the two it fails. Here is a code snippet from within the loop (yes, I am passing x_product_availability and other fields into the loop, all other fields work fine, just not the checkbox field):[-if field=x_property_city compare="=" checkbox={X_PRODUCT_AVAILABILITY}] [set passavail]1[/set] [-else][set passavail]0[/set] [/-if]
I would expect that the result would find the city id in field x_property_city and if that value is in the passed checkbox values {X_PRODUCT_AVAILABILITY} then the new variable passavail is set to 1. What I am getting is results that set passavail to 1 but x_property_city is not contained in {X_PRODUCT_AVAILABILITY}.
I get this in my test output:
1(1 is true) (this is the value of variable “passavail”)
Available in: 101, 98, 99, 94, 97, 103 (each of these is an ID from city taxonomy)
City: 95 (this is the id of the city a property resides in)
—–
1(1 is true) –
Available in: 101, 98, 99, 94, 97, 103
City: 97I can change the code to say
[-if checkbox={X_PRODUCT_AVAILABILITY} compare=”contains” field=x_property_city]
[set passavail]1[/set]
[-else][set passavail]0[/set]
[/-if]and I get the same result. Any suggestions? Please ??
- The topic ‘Comparing ACF Checkbox Values in a Loop’ is closed to new replies.