I have a Checkboxes field with options 1 and 2 and set to save nothing if unchecked. I can display the checked values using types_render_field() but my code to display content based on the value(s) saved for the field isn't generating the correct output. This is my code:-
$option1 = 'A';
$option2 = 'B';
$values = types_render_field( "apply-to-list", array("post_id" => '20', "separator" => ", " ) );
$values_arr = explode(', ', $values);
if (in_array($option1, $values_arr) && in_array($option2, $values_arr)) {
echo '<p>A and B</p>';
} else if (in_array($option1, $values_arr) && !in_array($option2, $values_arr)) {
echo '<p>A</p>';
} else if (!in_array($option1, $values_arr) && in_array($option2, $values_arr)) {
echo '<p>B</p>';
} else {
echo '<p>Neither A nor B</p>';
}
The uploaded image shows the value in the database is A but the output on the page is "Neither A nor B".
Any ideas please?
I discovered the values to check against are the checkbox title not the value saved to the database