I have a checkbox field with 3 choices (white, red, green) assigned to post. I display it in this way:
<?php $colors = get_field('smp2'); ?>
<?php if( $colors ): ?>
<?php foreach( $colors as $color ): ?>
<span class="scolor-<?php echo $color; ?>"></span>
<?php endforeach;
endif; ?>
How can I do to assign a link for each displayed choice? For example, if white is selected, it should link to white, etc…
Basically I need that clicking on any color/choice, WP shows posts with that color.
Hi @studiotopo
I believe all you need is to wrap the selected value within anchor tags as below.
<?php $colors = get_field('smp2'); ?>
<?php if( $colors ): ?>
<?php foreach( $colors as $color ): ?>
<a href="<?php echo link-to-the-color ?>"><span class="scolor-<?php echo $color; ?>"></span></a>
<?php endforeach;
endif; ?>
Hope this helps.