Ask Your Question
2

What is the solution to eliminate the error "Trying to get property of non-object" in WordPress?

asked 2022-01-17 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-12-16 17:00:00 +0000

scrum gravatar image

The error "Trying to get property of non-object" typically occurs when you are trying to access a property of an object that does not exist. There are a few solutions to eliminate this error:

  1. Check if the object exists before accessing its properties. You can do this using the isset() function, for example:
if ( isset( $my_object ) ) {
    $my_property = $my_object->my_property;
}
  1. Use the empty() function to check if the object is empty before accessing its properties:
if ( ! empty( $my_object ) ) {
    $my_property = $my_object->my_property;
}
  1. Debug the issue by adding some error checking code to your WordPress site. You can use the WPDEBUG and WPDEBUG_LOG constants to output errors to a log file, like this:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

With these constants set, you will be able to see any errors in the debug.log file in the wp-content folder of your WordPress site.

  1. Finally, you can also try disabling any plugins or themes that may be causing the issue by deactivating them one by one and checking if the error is still occurring.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-17 11:00:00 +0000

Seen: 10 times

Last updated: Dec 16 '22