Home Forums Add-ons Repeater Field Randomly get x amount of rows from another page


Randomly get x amount of rows from another page

  • Hey guys,

    I’m getting stuck with the repeater field. I’m trying to get an x amount of rows from another page and make the rows random. I’ve searched on the forums here but couldn’t make it work.

    The code that I’m now using displays 3 rows from another page, so that works. Now it only needs to display them random.

    <?php  $other_page = 67; ?>
    if( have_rows('smoelen', $other_page) ):
    $i = 0; 
    while( have_rows('smoelen', $other_page) ): the_row(); ?>
    <?php $i++; ?>
    <?php if( $i > 3 ):?>
    	<?php break; ?>
    <?php endif; ?>
    <div class="col-1-3">
    	<div class="image">
    		<img src="<?php the_sub_field('afbeelding'); ?>" alt="<?php the_sub_field('naam'); ?>">
    		<span class="overlay">
    			<p>“<?php the_sub_field('qoute'); ?>”</p>
    	<h3><?php the_sub_field('naam'); ?></h3>
    	<span><?php the_sub_field('functie'); ?></span>
    <?php endwhile; ?>
    <?php endif; ?>
  • Hi,
    In order to get the repeater from the other page, all you need to add is the post id for the same.

    such as

    $rows = get_field('slider_image',$other_page);

    Check out the following gist. It should help you out in getting the random rows from a repeater

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.