Support

Account

Home Forums Add-ons Repeater Field Limit and Random with Repeater Field

Unread

Limit and Random with Repeater Field

  • Sorry for the repetition but sent this via Help Desk 3 days ago and nothing and I need this ASAP, so trying my luck here to see if someone knows the answer to this.

    Anyways, here’s my question:

    I have this code extracted from http://support.advancedcustomfields.com/forums/topic/random-repeater/ (of course with my own field names)

    <?php $rows = get_field('slide_images', 'option'); 
    
                if($rows) $i = 0; 
    
                { shuffle( $rows ); 
    
                foreach($rows as $row) 
    
                { $i++; 
    
                if($i==13) break; 
    
                $image = wp_get_attachment_image_src( $row['image_to_slide'], 'full' ); 
    
                ?>
    
                <div class="class"><img src="<?php echo $image[0]; ?>" alt="<?php echo $image['alt']; ?>" /></div>
    
     <?php } } ?>

    for what I see, it should work fine. A different version using only limit and different style, works just perfect, like this:

    <?php if(get_field('slide_images', 'option')): 
    
                $i = 0;
    
                ?>
    
                 <?php while(has_sub_field('slide_images', 'option')): 
    
         $i++;     
    
         if( $i > 40 )
    
         {
    
             break;
    
         }
    
         ?>
    
             <div class="item"><img src="<?php the_sub_field('image_to_slide'); ?>" alt="" /></div>
    
         <?php endwhile; ?>
    
         <?php endif; ?>

    but the problem is I need shuffle, thus I can’t use this style. Bottom line, I need to use the simple PHP style, but I can’t make shuffle work, it simply outputs empty results, could you please tell me what am I doing wrong?

    Thank you in advance

    Fabio

    PS: I’m not a techie, so answers like “get data from here and then create your code” are of no help, otherwise I’d have done it already. I did a data dump and all the data is there, so I know for a fact the code is wrong, just can’t figure what exactly

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.