Home › Forums › Add-ons › Repeater Field › First row skipped when two on same page. › Reply To: First row skipped when two on same page.
I totally understand your explanation – thanks!
Ok, now the problem is that I’m a hack at PHP and don’t know how to write it very well 😛
Here are two attempts I made that didn’t work…
ATTEMPT #1 – WRAP IN FOREACH
Error Message = “Warning: Invalid argument supplied for foreach()”
<ul>
<?php
if(get_field(successbox, '117')):
foreach($rows as $row) {
$i=0;
echo '<li><a href="';
the_sub_field(link, '117');
echo '">';
the_sub_field(title, '117');
echo '</a><br>';
the_sub_field(subtitle, '117');
echo '</li>';
if($i<1) $i++;
else break;
}
endif;
?>
</ul>
ATTEMPT #2 – SEE REPEATER FIELD DOCS
Error Message = Parse error: syntax error, unexpected ‘,’, expecting ‘]’
<ul>
<?php
$rows = get_field(successbox, '117');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_field_1 = ' . $row[title, '117'] . ', sub_field_2 = ' . $row[subtitle, '117'] .', etc</li>';
}
echo '</ul>';
}
?>
</ul>
Can you please help me with my code snippet?
I’m really trying to learn PHP, but am struggling.
What I’m trying to produce is…
SCRIPT 1…
<subfield ‘title’ from row 1>
<subfield ‘subtitle’ from row 1>
<subfield ‘title’ from row 2>
<subfield ‘subtitle’ from row 2>
SCRIPT 2…
<subfield ‘photo’ from row 1>
Thank you for helping a PHP newbie!
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.