I'm trying to create an interface on the admin that will allow our authors to select top resources to place as an aside on our archive page. I'm trying to add a loop in addition to the original query run on the archive page. I have
- set up a page with a repeater field
- referenced this page in the archive to grab the repeater info (by naming the repeater the same as a taxonomy slug and using
get_queried_object()->slug
.
I'm running into some interference between the two loops:
archive.php:
//REPEATER LOOP
<?php
$slug = get_queried_object()->slug;
$posts = get_field($slug, 156053); //returns the post objects from the page with the repeaters
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
//post markup
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
//ORIGINAL ARCHIVE LOOP
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/content', get_post_format()); ?>
<?php endwhile; ?>
In this case, the first loop works as intended, and the original archive loop returns correct number of posts, but the postdata is from the original loop. (i.e. the first loop returns 3 results, the second loop returns 26 results but the first 3 are the same as the 3 from the original loop and the remainder are blank).
I have found that changing the of the repeater loop variable $post
takes away the conflict with the original archive loop, but then the repeater loop brings in the first post of the archive loop (x3, the number of posts designated by the repeater)
I'm really scratching my head over this one. Any help greatly appreciated!