PHP Notice: Trying to get property ‘post_title’ of non-object
-
This Notice is showing up in my debug.log.
I check the value of $post and it is null.
The page I was loading was the edit screen for a product.
As far as I know this variable is only set if the loop is started.
@see https://wordpress.stackexchange.com/questions/286241/global-post-shows-null-in-some-of-my-custom-post-types-archive-pages
So I assume that this isn’t the case.I get rid by editing contact-form-7-dynamic-text-extension.php:329 – 332
I changeglobal $post; //echo '<pre>'; print_r($post); echo '</pre>'; $val = $post->$key; return $val;
to
global $post; $val = ''; if($post instanceof WP_Post){ //echo '<pre>'; print_r($post); echo '</pre>'; $val = $post->$key; } return $val;
Therefore $post is checked before accessing it and if it is not an instance of WP_Post then the function will return an empty string and will not cause a notice anymore.
- The topic ‘PHP Notice: Trying to get property ‘post_title’ of non-object’ is closed to new replies.