Home › Forums › General Issues › wrap choice value into link
Hello, i found this code for show all choice values
<?php
$field = get_field_object('field_name');
if( $field['choices'] ): ?>
<ul>
<?php foreach( $field['choices'] as $value => $label ): ?>
<li><?php echo $label; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
but I need to wrap each value in a link, when you click on it, you will be taken to a page with an arbitrary post type containing the selected value

Just amend the HTML to include the $label in the a tag:
<?php
$field = get_field_object('field_name');
if( $field['choices'] ): ?>
<ul>
<?php foreach( $field['choices'] as $value => $label ): ?>
<li><a href="<?php echo $label; ?>"><?php echo $label; ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>

What does $label output?
How have you got the field setup?
What data are you entering?
the value of the checkbox type field
I have a checkbox type field with values: type1, type2, type3 and etc.
On custom post type archive page i want to show all values with links, on a page I want to output all field values with a link. When you click on the value link, open a page with posts that contain the selected value

You must be logged in to reply to this topic.
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.