Support

Account

Home Forums Backend Issues (wp-admin) Multiple values for checkbox choices Reply To: Multiple values for checkbox choices

  • Thanks, John, for your help. I appreciate it!

    It turns out that having HTML code in the checkbox field itself is not a good idea. When using the field, the selections don’t stick (i.e. the selected options are gone the next time you edit the post).

    So I went with only plain text values for the checkbox field and coded everything else in the template. Unfortunately, I read your sample code too late – going with “switch” would have been a good idea. As I’m not experienced with PHP, I handcrafted this subpar solution:

    $tools_choices = get_field('tools');
    
    if( $tools_choices ): ?>
      <h3 class="acf-title">Tools</h3>
    		  
      <?php foreach( $tools_choices as $name ): ?>
    
        <?php if( $name == 'Tool1' ): ?>
        <a href="https://url1.com/" target="_blank"><i class="fab fa-icon-x"></i><?php echo $name; ?></a>
        <?php elseif( $name == 'Tool2' ): ?>
        <a href="https://url2.com/" target="_blank"><i class="fab fa-icon-y"></i><?php echo $name; ?></a>
        <?php elseif( $name == 'Tool3' ): ?>
        <a href="https://url3.com/" target="_blank"><i class="fab fa-icon-z"></i><?php echo $name; ?></a>
        <?php else: ?>
        <p><i class="fab fa-icon-a"></i><?php echo $name; ?></p>
        <?php endif; ?>
    
      <?php endforeach; ?>
    
    <?php endif; ?>

    It’s not the best code, but it works. If I later have the time and energy, I might change my code to a cleaner version based on your input.

    Thanks again,
    Patrick