Home › Forums › General Issues › Link field values (checkbox) with url-s? › Reply To: Link field values (checkbox) with url-s?
Hi, I am trying to achieve a similar thing, using a checkbox to display name with a url in a list separated with hr line, so it looks nicer. The problem I am having is that I keep getting the first variable displayed in each list point. What am I missing? Thank you for your help.
This is the result I am getting (url is being linked from the word website, but not here):
Website1
Website1
Website1
Instead of:
Website1
Website2
Website3
<ul class="service-list">
<hr class="white-sep" />
<?php $count=0;
$globalCount=0;
$field_value = get_field('services_test2'); // returns array of selected values
$field_object = get_field_object('services_test2'); // gets field settings
$services = $field_object['choices'];
foreach($services as $value => $label){
$count++;
$globalCount++;
$class='';
$hr ='';
$hrstart ='';
if (in_array($value, $field_value)) {
$servicesList = "<a href='$value'>$label</a>";
}
if($count==2){
//$class='odd';
$hr='<hr class="black-sep" />';
} elseif($count==4){
//$class='even';
$hr='<hr class="white-sep" />';
}
if($count==4){
$count=0;
}
?>
<li class=""><?php echo str_replace('&', '<span class="pink">&</span>', $servicesList); ?></li>
<?php echo $hr; ?>
<?php } ?>
</ul>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.