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?
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?
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.