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.
<ul>
<?php shuffle(query_posts('post_type=commerce&showposts=6&orderby=rand')); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php
$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; ?>
</ul>
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.
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.