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

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There is a call right above line 3037 to get_post_status_object(). If the named status being requested as $status does not have an entry in the global $wp_post_statuses array, the function returns 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.

Viewing 1 replies (of 1 total)
  • The topic ‘Trying to get property out of non object’ is closed to new replies.