I am working on a function that I would like to access from anywhere within my theme when I call it. I am using the ACF flexible content field and I am retrieving a text field value. The value of my text field is repeating the last entry instead of looping through and grabbing all entries (in this case 2 flexible content fields on 1 page)

function linkboxdata() {

    global $post;   
    $data = array();

    $rows = get_post_meta( get_the_ID(), 'list_items', true );
    foreach( (array) $rows as $count => $row ) {
        switch( $row ) {

            case 'items':

                $section_title = get_post_meta( get_the_ID(), 'list_items_' . $count . '_section_title', true );



    $data = array(
        'title' => $section_title

    return $data;

    return false;


My function is being called within this block:

<div class="callout-link-box list-items">

    <div class="callout-content">

        <strong class="callout-title"><?php echo linkboxdata()['title']; ?></strong>

    </div><!-- /.callout-content -->

</div><!-- /.callout-link-box -->

No matter what I have tested so far it only shows 1 of the text fields values, I have tried moving the return $data a few places within my function.

Thank you!

  • Hi. Do you mean there should be multiple 'section titles' being output where you are calling the function? And, should each 'row' of data be outputting just the title, or should each be outputting the HTML you posted in the second snippet? – Dan. Nov 27 '16 at 20:38
  • @Dan. There is more data availble to get but I am looking to just retrieve title. So on my page I have my Flexible content field 2 times, another page I may only use it once. On the page with it called 2 times there are 2 instances of the title text box, each having unique content but its showing the content from the 2nd instance both times and ignoring that value in the 1st instance. – Danny Nov 27 '16 at 21:07
  • If you need the same function to return different values, then the function will need to accept an argument of some sort. If you don't need any particular titles to be shown in either of the two spots, then maybe you could pass an integer, which will be used in the foreach loop to 'break' when that number is reached – Dan. Nov 27 '16 at 21:21

Your Answer

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

Browse other questions tagged or ask your own question.