Trying to get property out of non object
-
Hi there, I really hope someone can help with this as I’ve been on it for a couple of days now. This is a bit of a strange one. I’ve written a plugin that implements a number of custom post statuses. For example the one I’m working on is ‘group_post’.
When I’m trying to load a single page view from a posts listing I’m getting the following error:
[25-Feb-2019 04:56:03 UTC] PHP Notice: Trying to get property 'public' of non-object in /wp-includes/class-wp-query.php on line 3037
This is an error in get_posts, specifically it’s trying to get the public value from the group_post post status object.
In order to troubleshoot the problem I hooked a filter on ‘posts_results’ and issued the following commands:
$test = get_post_status_object(get_post_status($results ) ); var_dump($test); var_dump($test->public);
The var_dump of $test returns a post status object, with a field of ‘public’ set to true.
The var_dump of $test->public returns NULL and gives the trying to get property of non object error.However if I use a PHP console and issue the same commands for the same post status it returns the true value no problem.
Under what circumstances does an object appear to not be an object?
Also to note: the output from my single post view returns as expected – I get to see the post.
Any advice on troubleshooting this further would be greatly appreciated.
- The topic ‘Trying to get property out of non object’ is closed to new replies.