Support

Account

Home Forums Front-end Issues How to show values from a checkbox ?

Helping

How to show values from a checkbox ?

  • Hello,

    I don’t manage to do a simple thing… I finded all the morning but nothing. I’d like to show values (taxonomy) in my single.php from a checkbox.

    How you do that ? I tried that for example an nothing :

    $field_obj = get_field_object(‘type_metier’);
    $metiers = get_field(‘type_metier’); // array of selected color values

    foreach($metiers as $val) {
    print $val;
    }

    Thanks for you help,
    Jonathan

  • If type_metier is a taxonomy field set to display as checkboxes,

    $terms = get_field('type_metier');
    if ( $terms ) {
      foreach ( $terms as $t) {
        $term = get_term( $t, 'taxonomy' );
        echo $term->name . '<br>';
      }
    }

    If you’re trying to just print values from checkboxes, it would be something like,

    $values = get_field('type_metier');
    if ( $values) {
      foreach ( $values as $v) {
        echo $v . '<br>';
      }
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to show values from a checkbox ?’ is closed to new replies.