Home › Forums › General Issues › Issues with for loop when switching from radio to checkbox
We have a site which used to have a radio button option for roles in custom post types. We had to switch that to checkboxes because multiple roles need to be selected for some posts.
That went fine but now the for loop that we had in place doesn’t work for posts with multiple roles selected. It still displays posts which have one role selected, however. I’d appreciate any help with this as it’s written in Twig and that’s completely foreign to me!
<section class="section people">
<div class="row row-17-column">
<h1 id="team" class="header-large center">Our Team</h1>
<div class="bio-profiles">
{% for team in team %}
<bio-profile bio-id="'{{team.ID}}'" :bio-length="{{team.biography|length}}">
<img slot="photo" src="{{TimberImage(team.photo).src}}" alt="{{TimberImage(team.photo).caption}}">
<h3 slot="name" class="header-small full-width">{{team.first_name}}<br>{{team.last_name}}</h3>
<p slot="position" class="profile-position">{{team.job_title}}<br />{{team.company}}</p>
<div slot="related" class="related-stories hide-small"></div>
<p slot="quote">“{{ team.quote }}”</p>
<p slot="bio">{{ team.biography }}</p>
</bio-profile>
{% endfor %}
</div>
</div>
</section>
The old field returned a single value (string). Any posts that have not been updated will continue to return a single value. A radio field can only have one value.
Any post updated or added after the change will return an array of values. A checkbox field can hold multiple values.
You will need to check for both conditions and something different for each. Either that or you will need to edit every existing post to update the field so that it will always return an array.
I haven’t got a clue how to incorporate any of this into twig because I don’t use it.
Thanks, John. We’re reaching out to some Twig devs to see if they have an answer.
The topic ‘Issues with for loop when switching from radio to checkbox’ is closed to new replies.
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.