0

I am building a site using Root's Sage Wordpress theme which uses the blade templating engine.

I have a repeater field in ACF with many post objects. When I foreach loop through the repeater to retrieve the post objects, I am getting a Notice: Trying to get property of non-object errors. When I turn off WP_Debug, these errors are not present and the following code works as expected.

Below is a snippet of the code used:


global $post; 

@foreach($page_column as $pages)


    {{-- If the link is internal --}}
    @if($pages['link_type'] === "Internal")

        @foreach($pages as $post)

            @php 

            setup_postdata($post); 

            @endphp

            <li class="footer__list-item">

                <a class="footer__link" href="{{get_the_permalink($post->ID)}}">{{$post->post_title}}</a>

            </li>

            @php wp_reset_postdata(); @endphp

        @endforeach

    @endif

@endforeach

Below is what is output:

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44
Home

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44
About

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44
Locations

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44
Case Studies

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44
Downloads

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

Notice: Trying to get property 'post_title' of non-object in /homepages/6/d142103519/htdocs/development-sites/newable-3.0/wp-content/uploads/cache/0df15fedcc33b7f94d22294aa741cea17fe36f28.php on line 44

What is interesting is you can see the code is working as intended because below most of the error messages, you can see the post title being output. I also do not understand why there are multiple errors thrown per page as the code is retrieving all the pages from the repeater field successfully.

From what I found when looking up the error, I added in the setup_postdata($post) to see if that would fix the issue however that does not seem to have worked.

What am I doing wrong here?

2
  • I would turn off the debug!
    – Elkrat
    Mar 13, 2019 at 13:14
  • @Elkrat I like to have it on whilst developing.
    – Gazz
    Mar 13, 2019 at 13:16

1 Answer 1

1

Nevermind, after a couple of minutes, I figured out the issue.

Instead of passing the $post->ID into get_the_permalink, I can just not pass any parameters in as the setup_postdata($post) takes care of this.

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.