Support

Account

Home Forums Front-end Issues Displaying Checkbox Values gives Error

Solving

Displaying Checkbox Values gives Error

  • I’m using the documented code for showing multiple checkbox values:

    <?php echo implode(', ', get_field('field_type_use')); ?>

    where ‘field_type_use’ is my field’s name.

    I’ve tried a number of variations, including using ‘the_field’ but keep getting the same error:

    Warning: implode() [function.implode]: Invalid arguments passed in /home/tdevelop/public_html/wp-content/themes/tsl_wp/templates/fieldgroups.php on line 765

    765 is the line of the code above. So my question is what am I doing wrong? I have three checkboxes that could be shown here. And for the one post i’m testing this on, there is definitely a checkbox value.
    I’ve looked through the code and have no idea why its not showing up.

    Any help would be great.

    If it matters at all, i’m also using this custom code to call all fields from a field group, and the checkboxes are getting missed, so i am trying to manually add them. I would be trying to add the code I showed above just under the ‘echo <ul’ line:

    //start of each field group
    echo '<div class="col-sm-6">';
    echo '<h3>Facilitiy Details</h3>';
      $group_ID = 13255;
    $fields = array();
    $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
    echo '<ul class="list-unstyled">';
    if( $fields )
    {
      foreach( $fields as $field_name => $field )
      {
        $value = get_field( $field['name']);
        if ($field['choices']){
          $map = array(
           'yes' => '<i class="icon-ok"></i>'       
           );
          $value = $map[ $value ];
        } else {
        }
        if( $value && $value != 'no') {
          echo '<li>' . $field['label'] . '&nbsp;' . $value . '</li>';
      }
    }
    }
      echo '</ul>';
    echo '</div>';
    //end of each field group

    Thanks!!

  • Hi @aaronrobb

    The code you have posted above does not use the implode function.

    Perhaps you need to debug your code to make sure it can be implodeed.

    You can debug data by printing it like so:

    
    <?php 
    
    echo '<pre>';
    	print_r( get_field('field_type_use') );
    echo '</pre>';
    die; ?>
    

    Perhaps I should let you know that your above code is very complicated to achieve a very simple function. Perhaps you should look into the get_fields and get_field_objects function.

    Thanks
    E

  • I’m having the same problem. I’m using the documented code (which, I mean, it’s documented, shouldn’t it just work?). Returning the same error as aaron. All I want to do is return all checked checkbox values in an array, and comma separate them. Is that not what the documented code is supposed to do? Some help with this would be great.

    The documented code that doesn’t work.
    <?php echo implode(', ', get_field('field_name')); ?>

  • Ah. I figured it out. I was trying to display the checkbox values from a custom taxonomy on the taxonomy page. My code ended up looking like this.

    
    $queried_object = get_queried_object();
    $Skills = get_field('skills', $queried_object);
    echo implode(', ', $Skills);
    

    Haha man, that was driving me crazy.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Displaying Checkbox Values gives Error’ is closed to new replies.