Support

Account

Home Forums General Issues How to show only one row using the_sub_field

Solving

How to show only one row using the_sub_field

  • Hi!
    I have 4 row in the layout.
    Using the following code

    if(have_rows('counter_repeater')): 
    while(have_rows('counter_repeater')):the_row(); 
    echo"<p>";the_sub_field('counter_number');
    echo"</p>";
    endwhile;  
    endif;  

    I can show them on the homepage as

    <p>value1</p>
    <p>value2</p>
    <p>value3</p>
    <p>value4</p>

    My question is I want to show only
    <p>value 3</p>
    on the screen. How can I do it?

    I want to get this values seperately so I can show something like this:
    <tr>
    <td>name:</td><td>value1</p>
    </tr>
    <tr>
    <td>address:</td><td>value4</p>

    Many Thanks for your help.

  • you could use:

    $row1 = get_field('counter_repeater_0_counter_number'); //for first row
    $row2 = get_field('counter_repeater_1_counter_number'); //for second row
    ...
    echo "<tr><td><p>name:</p></td><td><p>";
    echo $row1;
    echo "</p></td><tr>";
    ...

    instead of your if-while loop (just add 3+4 row & echo row 2-4 where you wish)

  • You can also use get_field('counter_repeater'); which will return an array and then target whichever line you need.

    $array = get_field('counter_repeater');
    echo $array[2]['counter_number'];

    Cleaner than strings I’d imagine.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘How to show only one row using the_sub_field’ is closed to new replies.