1

I have a custom field in WP called what_we_do_textarea_two. what_we_do_textarea_two is a simple repeater field which allows you to add another item to a list.

what_we_do_textarea_two has a subfield called list_item:

enter image description here

Since this list may have x amount of listings, what is the best way to retrieve the data from that field? At the moment I have:

$textareaTwo = get_sub_field("list_item");
if ($textareaTwo && count($textareaTwo)>0){
    foreach ($textareaTwo as $textareaTwos){
        $res = get_post($textareaTwos);
        echo'Test'.$res; 
    }    
} 

But it doesn't display anything? At the moment I have two listings in the repeater, so it should show two listings? I imagine it'll be a for loop since I want all data from the list the be displayed, but unsure as to why mine doesn't work?

2
0

Please use below code to get list item

<?php

// check if the repeater field has rows of data
if( have_rows('what_we_do_textarea_two') ):

    // loop through the rows of data
    while ( have_rows('what_we_do_textarea_two') ) : the_row();

        // display a sub field value
        the_sub_field('list_item');

    endwhile;

else :

    // no rows found

endif;

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.