Support

Account

Home Forums General Issues Issues with for loop when switching from radio to checkbox

Solving

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">&ldquo;{{ team.quote }}&rdquo;</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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.