Home › Forums › Add-ons › Repeater Field › Get all repeater images from all posts but only from 3 categories › Reply To: Get all repeater images from all posts but only from 3 categories
I figured this out. In case anyone else wants to know…
<div class="sponsors">
<?php
global $post;
$the_query = new WP_Query( array(
'post_type' => 'contestants',
'tax_query' => array(
array(
'taxonomy' => 'year_type',
'field' => 'slug',
'terms' => array( 'term_1', 'term_2', 'term_3' )
)
))
) ;
if($the_query->have_posts()){
while ( $the_query->have_posts() ) {
$the_query->the_post();
if( have_rows('sponsors', $post->ID) ):
// loop through the rows of data
while ( have_rows('sponsors') ) : the_row();
// display a sub field value
$image = get_sub_field('sponsor_logo');
$url = get_sub_field('sponsor_url');
$name = get_sub_field('sponsor_name');
?>
<div class="sponsor"><a href="<?php echo $url; ?>" target="_blank" title="<?php echo $name; ?>"><img src="<?php echo $image; ?>" /></a></div>
<?php endwhile;
else :
// no rows found
endif;
}
}
?>
</div>
Please mark this thread closed. Thank you.
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.