Home › Forums › Add-ons › Repeater Field › Query posts within taxonomy via repeater › Reply To: Query posts within taxonomy via repeater
So I looked a bit closer at your code, and mine, there were other errors in both. I think this might do what you’re looking for.
<!-- Nav Tabs -->
<ul class="nav nav-pills">
<?php
if (have_rows('home_categories')) {
$i = 0;
while (have_rows('home_categories')) {
the_row();
$term = get_sub_field('categories');
?>
<li class="<?php
if ($i == 0) {
echo 'active';
}
?>"><a href="#<?php
echo $term->name; ?>" data-toggle="tab"><?php
echo $term->name; ?></a>
</li>
<?php
$i++;
}
}
?>
</ul>
<?php
// if your not getting anything below try reset_rows()
// uncomment the next line
//reset_rows();
?>
<!-- Tab Content -->
<div class="tab-content clearfix">
<?php
if (have_rows('home_categories')) {
$i = 0;
while (have_rows('home_categories')) {
the_row();
// moved this line up before query that uses it
$term = get_sub_field('categories');
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
// corrected terms to use correct value
'terms' => array($term->term_id)
)
),
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'ASC',
);
// if your still not getting anything
// uncomment and make sure the query args look right
//echo '<pre>'; print_r($args); echo '</pre>';
// renamed query to not use global $post variable
$query = new WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
?>
<div class="tab-pane fade<?php
if ($i == 0) {
echo ' active';
}
?>" id="<?php echo $term->name; ?>">
<?php
the_post_thumbnail('thumbnail', array('class' => 'img-responsive img-thumbnail'));
?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</div>
<?php
} // end while have posts
$i++;
} // end while have rows
wp_reset_postdata();
} // end if have rows
?>
</div>
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.