Support

Account

Home Forums ACF PRO Add value as classes checkbox

Solved

Add value as classes checkbox

  • Hello,
    I would like to add classes on a list of checkboxes. I add value to each choice :
    wifi : WIFI
    tv : TV Sat
    menage : Ménage
    parking : Parking privé
    acces : Accès sécurisé

    I use the following code :

    <?php $field = get_field_object('equipement');
    $equipements = $field['value'];
    if( $equipements ): ?>
    <ul>
    <?php foreach( $equipements as $equipement ): ?>
    <li><class="<?php echo $field['choices'][ $equipement ]; ?>"><?php echo $field['choices'][ $equipement ]; ?></li>		
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    If someone can help me. Thank you

  • 
     <?php
    $field = get_field('equipement');
    if( $field ): ?>
    <ul>
    	<?php foreach( $field as $value ): ?>
    		<li class="<?php echo $value; ?>"><?php echo $value; ?></li>
    	<?php endforeach; ?>
    </ul>
    <?php endif; ?>
    
  • It’s not exactly what I want. But I find out the solution :

    <?php 	$field = get_field_object('equipement');
    	$equipements = $field['choices'];
    	$equipements_selected = $field['value'];							
    	if (sizeof($equipements_selected)>0) {
    	?>
    	<ul>
    	<?php foreach($equipements_selected as $equipClass) {
    		$equipLabel = $equipements[$equipClass];
    	?>
    	<li class="<?php echo $equipClass; ?>"><?php echo $equipLabel; ?></li>
    	<?php	} // foreach ?>
    	</ul>
    	<?php 	} // if sizeof ?>

    Thank you for your answer.

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

You must be logged in to reply to this topic.