Please tell me how can I add a class to each value from the list fields “Choices”?
For example, I have values:
ColorRed: Red
ColorGreen: Green
Load and display multiple selected values like this:
<?php
$colors = get_field( 'color' );
// Create a comma-separated list from selected values.
if( $colors ): ?>
<p>Color: <span><?php echo implode( ', ', $colors ); ?></span></p>
<?php endif; ?>
And I would like to get the following code in the frontend:
<p>Color: <span class="ColorRed">red</span><span class="ColorGreen">Green</span></p>
<p>Color: <span class="<?php echo esc_attr($color['value']); ?>"><?php echo esc_html($color['label']); ?></span></p>
Set the field to return “Both” value and label. See the examples on this page https://www.advancedcustomfields.com/resources/checkbox/