Home Forums Front-end Issues Checkboxes and icons


Checkboxes and icons

  • I’m trying to show icons to represent wash care symbols for checkbox fields in ACF.

    I have the following code, which only outputs the bullet points and no labels:

    // Load field settings and values.
    $field = get_field_object(‘careguide’);
    $careguide = $field[‘value’];

    // Display labels.
    if( $careguide ): ?>

      <?php foreach( $careguide as $care ): ?>

    • <?php echo $field[‘choices’][ $care ]; ?>
    • <?php endforeach; ?>

    <?php endif; ?>

    I would like to show a wash care symbol (image) in place of the selected options, but I seem to be going around in circles.

    Any help would be appreciated.

  • I don’t understand why you are doing this when you are only using the selected values

    $field = get_field_object(‘careguide’);
    $careguide = $field[‘value’];

    when you could just do this

    $careguide = get_field('careguide')

    But that’s neither here nor there.

    You need to output an image based on the value

    foreach ($careguide as $care) {
      if ($care == 'some value') {
        ?><img srd="some image url"><?php
      } elseif ($care == 'some other value') {
        ?><img srd="some other image url"><?php
      } // .... etc

    Or you could set the value in the checkbox field to the actual URL
    radio field choices

    url-1.jpg : label 1
    url-2.jpg : label 2
    url-3.jpg : label 3


    foreach ($careguide as $care) {
      ?><img src="<?php echo $care; ?>"><?php 
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.