Support

Account

Forum Replies Created

  • So, I ended up doing this:

    <?php if( have_rows('section_content') ):
    	$rows = array();
    	$i = 0;
    	while ( have_rows('section_content') ):
    		the_row();
    		$rows[$i] = get_sub_field('content_option');
    		$i++;
    	endwhile;
    	$i = mt_rand(0,count($rows)-1);
    	echo $rows[$i];
    else:
    	// some other stuff
    endif; ?>

    Hackfest 2015! But at least I’m getting the results I need. I’m guessing this isn’t very efficient, but I’m going to end up putting caching on this, and we’re talking about a very small audience (maybe 1000 visitors per month across 6 sites). So I think it will end up working out fine.

    Still, I would love it if there’s a more native way to do what I’m doing, where I just pull one result, instead of pulling all of them and then selecting one from an array. It feels dirty…

Viewing 1 post (of 1 total)