Support

Account

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.