Quantcast
Channel: Tagged with repeater - Plugin Support
Viewing all articles
Browse latest Browse all 160

Display results from the repeater field in a random order

$
0
0

I have the repeater field setup so that is displays ten results. I want these results to pop up in a random order everytime the page is refreshed. I have 10 results at the moment. I've found solutions for displaying one results randomly, but not multiple results randomly.

So, this is what i have right now:

 $sample_tweets = get_field('social_media_tweets');
 $random_rows = array_rand( $sample_tweets, 10 );

 if( is_array( $random_rows ))
 {

echo "<div class='tweet-samples-box'>";


    foreach($random_rows as $row)
    {

        $even_odd = ( 'row-odd' != $even_odd ) ? 'row-odd' : 'row-even';

        echo "<div class='".$even_odd."'><div class='padding-ten'><div class='tweet-text'>".$sample_tweets[$row]['sample_tweet_text']."</div><div class='tweet-button'><a href='http://twitter.com/intent/tweet?text=".urlencode($sample_tweets[$row]['sample_tweet_text'])."' target='_blank'>Tweet Now &raquo;</a></div></div></div>";


    }

echo "</div>";
 }

Viewing all articles
Browse latest Browse all 160

Trending Articles