Home Forums Front-end Issues Repeater / Select fields filled Reply To: Repeater / Select fields filled

  • Hi @elliot,

    Thanks to take the time to answer me.
    Here is my question :

    On the home page, I show 6 Tips randomly coming from several post (one hundred). The problem is that each post do not necessarily tips. Here is my code to display randomly.

    <?php shuffle(query_posts('post_type=commerce&showposts=6&orderby=rand')); ?>
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    										$rand = rand(0,1);
    										$i = 0;
    <?php while(the_repeater_field('bons_plans_de_votre_magasin_commerce_detail')): ?>
    <?php if(get_sub_field('titre_commerce_detail')){ ?>
    <?php if($rand == $i): ?>
    <li><a href="<?php the_permalink(); ?>" target="_blank"><span><?php the_sub_field('titre_commerce_detail'); ?></span></a></li>
    <?php endif; ?>	
    <?php } ?>
    										<?php endwhile; ?>
    <?php endwhile; endif; ?>	

    The problem is that when the loop is looking for tips at random, it may choose to post item who have no tips. But she decides to show anyway.

    For example, currently on my website, I have two tips on an item and one tips on another item. But knowing that there are hundred articles and all the others have no tips while on my homepage nothing appears, you have to refresh several times to appear a good plan from time to time …

    How to tell the loop to not display a tips if it does not been found in this section and move to look for another instead.

    I hope I was clear ..

    Thank you @ elliot.