Hi all, I am trying to link a repeater to another page and pull content from the row clicked on. I have successfully done this but I am hoping for a better or faster way. In the page with the repeater, I have created a link such as get-the-row/?the_row_index=10. In the get-the-row page I have created the script such as:
<?php
if ($_GET[‘the_row_index’]) {
$otherPost = 99;
$postID = $_GET[‘the_row_index’];
}
?>
<?php if( have_rows(‘the_repeater’, $otherPost) ): ?>
<?php while( have_rows(‘the_repeater’, $otherPost) ): the_row(); ?>
<?php $rowID = get_row_index(); ?>
<?php if ($rowID == $postID) : ?>
Sub Field 1: <?php the_sub_field(‘sub_field_number_1’); ?>
Sub Field 2: <?php the_sub_field(‘sub_field_number_2’); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
While this works just fine, I’m wondering if there isn’t a way to just pull info from the one row instead of iterating through all the rows until I get to the one I want? Thanks in advance.
You can if you want to use get_post_meta() instead of ACF functions. However, this will return unformatted values and you’ll need to format them yourself if needed. The meta keys for repeaters look like "{$repeater_name}_{$row_index}_{$sub_field_name}"
and you would use something like get_post_meta($post_id, $field_name, true)
https://developer.wordpress.org/reference/functions/get_post_meta/
I should add that row indexes in the DB always start a 0 (zero)