I am trying to set up a page that displays a list of employees. There is about 60 of them, so they are set up as a custom post type named people. I have a taxonomy as well that allows the employees to be tagged with their job title, which is named people-category.
I have a repeater set up so the client can easily display the list of employees and have that list be grouped by the employee’s job title. So the end result should be:
Next Job Title
And so forth.
I have the repeater working and the taxonomy, but for some reason, the result is showing the correct list of employees multiple times followed by the list of every employee multiple time for each row of the repeater. I can’t seem to figure out why this is happening. It seems like the query isn’t being reset properly and it is repeating over and over. Here is my code:
<?php if( have_rows('people_list') ): ?> <?php while( have_rows('people_list') ): the_row(); ?> <li class="clear the-content"> <h3><?php the_sub_field('group_title'); ?></h3> <?php $terms = get_sub_field('people_category'); array($terms); ?> <?php foreach ($terms as $term): ?> <div class="clear pad-top-20"> <?php // The Query query_posts( array( 'post_type' => 'people', 'people-category' => $term, 'posts_per_page' => -1 ) ); // The Loop while ( have_posts() ) : the_post(); ?> <div class="col-1-3 pad-left-20 pad-right-20 pad-bottom-20 client-event-column ipp-width-100 ipp-pad-left-0 ipp-pad-right-0"> <div class="font-blue font-weight-700"> <?php the_title(); ?> </div> </div> <?php endwhile; // Reset Query wp_reset_query(); ?> </div> <?php endforeach; ?> </li> <?php endwhile; ?> <?php endif; ?>
I have used a variation of this code before to achieve the same result, just never in a repeater. So you can see why I am at a loss. Any help would be appreciated.
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!
© 2023 Advanced Custom Fields.