Support

Account

Home Forums Front-end Issues I don\'t get the checkbox field value

Solving

I don\'t get the checkbox field value

  • I try to have the values ​​of a checkbox field, but I don’t know what I’m doing wrong. I’m using this code:

    <? PHP
     $option = the_field('Monday'); 
    if($option ="a" ){ $color ="coral";} 
    elseif($option = "b") { $color ="blue"; } 
    elseif($option ="c" ){ $color ="green"; } ? > 
    <style> .Friday{ background color: <? Php echo $color; ? >; } </style>

    But it always returns the same value as the “a”, and when I put “==” or “===”, I don’t get any results

  • A checkbox field returns an array of values, labels or both.

    Assuming that you are returning values

    
    if (in_array('a', $option)) }
    
    } elseif (in_array('b', $option)) {
    
    } elseif (in_array('c', $option)) {
    
    }
    
  • Using that code I get this error:

    Warning: in_array() expects parameter 2 to be array, null given in

  • Then there is not a field name “Monday” or the field has no value.

    
    $option = the_field('Monday'); 
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.