If you put WordPress into debug mode with:
You may get the following warning
"Notice: Trying to get property of non-object in /yourpath/wp-content/plugins/yet-another-related-posts-plugin/includes.php on line 274"
This appears to be caused by this single line of code:
$type = ($post->post_type == 'page' ? array('page') : array('post'));
My interpretation of the above code is that it attempts to set the variable
$typebased on the object
$postmay not actually be an object, if for example you are viewing a regular WordPress page.
By rewriting this code with the an
is_object($post)test, you can avoid this notice.
Please note: this also seems to address the following warning:
WordPress database error: [Unknown character set: 'utf'] set names utf-8
@robbyslaughter I’m unable to reproduce this issue. You say
$postmay not be an object “if for example you are viewing a regular WordPress page”. Two things: WordPress posts when displayed also use the global
$postvariable. It should always be an object. Second, if you are displaying related posts on a page, you probably did so by calling a function such as
related_pages()manually in your theme, not using the
How are you displaying related posts? Via the “automatically display” option, or by adding code to your theme? Do you only get this warning on pages but not posts?
First: it’s just a notice, not a warning or an error. It only appears on my site if I change WP_DEBUG to true. I’m not suggesting that this is in any way critical, I’m just documenting this issue in case someone else happens along it later.
I don’t believe the notice solely connected to YARPP. I am using the Improved Include page plugin, and it appears each time a page is “included” with this plugin. I think when Improved Include executes, it does not create a
$postvariable in the same way as part of the regular loop. My perception that the issue was tied to regular WordPress pages was in fact a red herring; it seems to only occur with use of Improved Include.
In any case, we are not using the automatic insertion feature of YARPP. Instead, we are in fact calling
Since the function
yarpp_defaultgets added as a filter to
the_content, it seems like there are cases in which this function could be called outside of The Loop. So, it would seem like better coding not to assume
$postexists and instead to check as I have suggested.
- The topic ‘[Plugin: Yet Another Related Posts Plugin] Resolving "Notice: Trying to get property of non-obj’ is closed to new replies.