Custom Fields
Re-Envisioned
Support MB Views Loop through taxonomy parent, and child terms

  • Creator
    Topic
  • #20319
    Resolved jason@zrimarketing.com
    Participant

    In the code below I’m trying to loop through the parent terms. And display the subsequent child terms. So, in this example the parent term is the State, and the child terms are the Cities in that state. The first function, mb.get_terms(), is working correctly. It returns the correct list of parent terms. However, the second function, mb.get_term_children(), does not return the child terms. Think the term.ID is not present, and that is causing this function to not work properly.

    
        <section id="home-service-areas" class="pv4">
            <h2 class="tc">Service Areas</h2>
            <div class="flex-ns justify-center items-center center mw9 ph3">
                {% set args = { taxonomy: 'service-area', parent: 0 } %}
                {% set terms = mb.get_terms( args ) %}
                {% for key, term in terms %}
                <div class="w-25-ns mh4 mv4">
                    <h3>{{ term.name }}</h3>
                    <ul>
                        {% set termchildren = mb.get_term_children( term.ID, 'service-area' ) %}
                        {% for key, child in termchildren %}
                        <li>{{ child.name }}</li>
                        {% endfor %}
                    </ul>
                </div>
                {% endfor %}
            </div>
        </section>
    
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.