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.
]]>null
, which will cause the non-object notice when line 3037 code tries to get the public property from null
.
So why is your status not in the global $wp_post_statuses? This is what you need to resolve. Did you neglect to register_post_status() by any chance?
No idea why you get something different in PHP console. Something different in the environment I suppose. All that matters is the environment where your code is actually used. It’s OK to temporarily insert debug code into core files. Just don’t forget to go back and remove it after the fact. If all else fails, it’ll be removed in the next update, or you can re-install the last update.
]]>