-
-
Save davemac/d79358b2623b1fba8d090a9f3768fbb1 to your computer and use it in GitHub Desktop.
ACF Repeater - Grab First/LAst or Random Single Data Row
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//My ACF Fields for reference | |
//testimonials - field group | |
//testimonial - sub-field | |
//testimonial_header - sub-field | |
//First Repeater Row in Array | |
$rows = get_field( 'testimonials', 348 );// grab all rows from page ID | |
$testimonial_content = $rows[0]['testimonial'];//grabs first testimonial content- change number in both for different row | |
$testimonial_header = $rows[0]['testimonial_header'];//grabs first testimonial header | |
$first = '<blockquote>' . $testimonial_content . '</blockquote><p>' . $testimonial_header . '</p>'; //set surrounding HTML markup | |
echo $first; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//My ACF Fields for reference | |
//testimonials - field group | |
//testimonial - sub-field | |
//testimonial_header - sub-field | |
//Last Row in Array | |
$rows = get_field( 'testimonials', 348 ); // get all the rows from and page ID | |
$end_row = end( $rows ); // get the end row | |
$testimonial_content = $end_row['testimonial' ]; // get the sub field value | |
$testimonial_content = $end_row['testimonial_header' ]; // get the sub field value | |
$last = '<blockquote>' . $testimonial_content . '</blockquote><p>' . $testimonial_content . '</p>'; //set surrounding HTML markup | |
echo $last; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//My ACF Fields for reference | |
//testimonials - field group | |
//testimonial - sub-field | |
//testimonial_header - sub-field | |
//Random Single Repeater Row in Array | |
$rows = get_field( 'testimonials', 348 ); // grab all rows from page ID | |
$rand_row = $rows[ array_rand( $rows ) ]; // grab a random row | |
$testimonial_content = $rand_row['testimonial' ]; // get the sub field value | |
$testimonial_content = $rand_row['testimonial_header' ]; // get the sub field value | |
$random = '<blockquote>' . $testimonial_content . '</blockquote><p>' . $testimonial_header . '</p>'; //set surrounding HTML markup | |
echo $random; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment