Support

Account

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!