Hello,
I tried it for hours but I think my php is not good enough. Maybe anyone can help?
I habe an ACF-Checkbox with “first” and “second”.
Now I work in the functions.php to make a function with an if/then.
$variable = get_field('acfField');
if ($variable == "first") {
echo "do this";
}
if else ($variable == "second") {
echo "do that";
}
}
Maybe i think anywhere completely wrong. Please help!
Thanks
Since I’ve now spent too much time trying to do the same thing, and finding this post with no update, I wanted to post a solution for others (or myself when I search again)
Even though “value” is selected on the checkbox, the item is still stored as an array. As such, you do just a normal “get_field” as you’d be getting an array that returns “1”.
We need the info contained in the array.
$variable = get_field(‘acffield’);
$var_value = $variable[‘value’];
Now we can see the values;
if ($var_value == “first”) {
echo “do this”;
}
elseif ($var_value ==”second”) {
echo “do that”;
}
Hopefully that gets someone else on the right track.