Using App to return ACF repeater field, coming through empty

In my front page controller, I have a function that I would like to return the value of an ACF repeater field ($friends_logos), but it’s coming through blank. Other ACF fields ($friends_title) are coming through as expected everywhere this partial is used.

Wondering if missing something key here in the logic. Is that data not allowed? Do I have to declare it or something?

Here is my Front Page Controller:

    <?php

namespace App\Controllers;

use Sober\Controller\Controller;

class FrontPage extends Controller
{
    public function signup_img_t()
    {
        return \App\asset_path('images/footer/separator-whitebg.svg');
    }
    public function friends_title()
    {
        return get_field('friends_&_supporters_section_title', 'options');
    }
    public function friends_logos()
    {
        return get_field('friends_supporters_logos', 'options' );
    }

}

Here is my template part

  <?php 
echo $friends_logos." = friends logos<br/>";
echo var_dump($friends_logos);
$logos = get_field('friends_supporters_logos', 'options' ); ?>

@if ($logos)

<div class="white-bg petrol">
    <img loading="lazy" src="{!! $getinvolved_menu_imgt !!}">
    <div class="container py-5 ">
        <div class="col">
            <div id="supporters">
                <h3 class="text-center p-5 my-5 head coral">{!! $friends_title !!}</h3>
                <div class="d-flex justify-content-between flex-wrap">
            
                    @foreach( $logos as $logo )
                        @php
                            $img = $logo['friends_logo'];
                            echo wp_get_attachment_image( $img, 'full' ); 
                        @endphp

                        @if ($logo['friends_link'])
                            <a href="<?= $logo['friends_link'] ?>" title="<?= $logo['friends_title'] ?>" target="_blank">
                            <img loading="lazy" src="{{ $img }}" class='p-1'>
                            </a>
                        @else
                            <img loading="lazy" src="{{ $img }}" class='p-1'>
                        @endif
                    @endforeach
                </div>
            </div>
        </div>
    </div>
</div>

@endif

And here is the ACF

 {
        "key": "field_60f57b90d7d57",
        "label": "Friends & Supporters Logos",
        "name": "friends_supporters_logos",
        "type": "repeater",
        "instructions": "This will fill the friends and supporters area with the approproate logos.  The more you put in her the larger your co2 score for this page so try and be moderate! The co2 calculator at the bottom will update once per day with a new score so keep an eye on that if you add a lot of logos and check the score again the next day.",
        "required": 0,
        "conditional_logic": 0,
        "wrapper": {
            "width": "",
            "class": "",
            "id": ""
        },
        "collapsed": "",
        "min": 0,
        "max": 12,
        "layout": "table",
        "button_label": "Add Another Logo",
        "sub_fields": [
            {
                "key": "field_60f57bb7d7d58",
                "label": "Logo",
                "name": "friends_logo",
                "type": "image",
                "instructions": "Please compress your image using https:\/\/tinypng.com\/ to achieve the minimum filesize possible.",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "return_format": "url",
                "preview_size": "medium",
                "library": "all",
                "min_width": "",
                "min_height": "",
                "min_size": "",
                "max_width": 180,
                "max_height": 180,
                "max_size": "0.25",
                "mime_types": ".png, .jpg"
            },
            {
                "key": "field_60f57c4565dbd",
                "label": "Link",
                "name": "friends_link",
                "type": "url",
                "instructions": "Use this to add a link to the supporter.",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": ""
            },
            {
                "key": "field_60f5a84e0e2ab",
                "label": "Title",
                "name": "friends_title",
                "type": "text",
                "instructions": "Giving the proper name of the organisation you are linking to will help with site SEO.",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": ""
            }
        ]
    },

THank you for any help in my understanding!

What’s going on here? echo $friends_logos." = friends logos<br/>"; will presumably throw an error because you’re trying to echo an array (or you would be, if that returned actual data).

When I’m debugging something like this, I usually like to go back up the chain as far as possible, so I’d probably start by putting a var_dump( get_field( 'friends_supporters_logos', 'options' ); die(); in the Controller and seeing what output I got there. If that returned nothing, then I’d try the same thing but in something like functions.php that’s executed even earlier. You can also use wp_load_alloptions() to make sure your data is actually being stored where you think it is.

Thank you so much for your reply! It gave me the confidence that it should be working and actually in the end there did seem to be some data glitch with ACF. I renamed the specific field in ACF, resaved the page and lo and behold was working as expected. Thanks for your patience!

This topic was automatically closed after 42 days. New replies are no longer allowed.