Home › Forums › Add-ons › Repeater Field › How does one target a specific row in a repeater field with sub fields
I’d add a count to the loop and assign the count number as an id/class.
E.g:
<?php
$counter = 0; //this sets up the counter starting at 0
if(get_field( 'repeater_field' )) {
echo '<div>';
while(has_sub_field('repeater_field')) {
$counter++; // add one per row
echo '<div id="row-' . $counter . '"> STUFF </div>';
}
echo '</div>';
}
?>
Hi @john.marcello
Your title can be interpreted in a variety of ways.
Do you want to add an id attribute to an element like the code exmaple above?
Do you want to get all sub field values from row 1?
Do you wan to get all sub field values from row x, where sub field y = ‘abc’?
A clear explanation would be great.
Thanks
E
Hi I guess I realized this after the fact…So here is what I want to be able to do:
I have a repeater field (called author) with three sub-fields (called book, title, year). There are two “rows” meaning, two entries in the repeater field group.
So something like:
Book1, Title1, Year1
Book2, Title2, Year2
I am looking to write some conditional like
if (author_id == "21") :
<display the data for row 1>
endif;
Hi @john.marcello
How does author_id == "21"
relate to the first row in the repeater field? There is nothing in that row of data that contains the author_id number ’21’
Thanks
E
Just an example for now to show the conditional. But what I am actually trying to do is associate a row with an author_id (some user data). So if a post is by a certain author, it will display an associated row of data about that particular author.
Hi @john.marcello
Sorry, but your last comment has baffle me as to how I can help. You seem to understand the basics of a conditional statement:
if (author_id == "21") :
<display the data for row 1>
endif;
Perhaps you don’t understand how to get the sub field value to compare against? You can use a function called get_sub_field to do this.
Please read the docs to learn more
The topic ‘How does one target a specific row in a repeater field with sub fields’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.