Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.