Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My php_error.log in my console (locally on OSX) is reporting 3 PHP Notices. The PHP Notices only appear when browsing each admin page in the back-end for a site (running multisite) that uses a child theme. The child theme uses the parent theme's sidebar.php which the code below is placed in.

The PHP notices do not show for the site that uses the actual parent theme. Also, if I make another sidebar.php in the child theme, then the notices are still present. Interestingly, these notices do not appear when browsing the site locally, and everything works as expected. They only appear when browsing around the admin. The code in my sidebar is the exact code from this page on the WP Codex.

The exact code is:

<?php
 if($post->post_parent) {
 $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
 $titlenamer = get_the_title($post->post_parent);
}

else {
 $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
 $titlenamer = get_the_title($post->ID);
}

if ($children) { ?>

<h2> <?php echo $titlenamer; ?> </h2>
<ul>
  <?php echo $children; ?>
</ul>

<?php } ?>

Any the PHP notices are:

PHP Notice:  Trying to get property of non-object in sidebar.php on line 10
PHP Notice:  Trying to get property of non-object in sidebar.php on line 16
PHP Notice:  Trying to get property of non-object in sidebar.php on line 17

The lines in question from the above code are:

if($post->post_parent) { // line 10
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); // line 16
$titlenamer = get_the_title($post->ID); // line 17

Any ideas why these notices would be appearing in the admin pages and only for the child theme? Should I just ignore them?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

That's pretty simple:

You're trying to get the parent property from the $post object, but that is either NULL or simply not attached. In both cases, you are

Trying to get property of non-object

from the $post object.

Simply check if ( isset( $post->parent ) ) { /* do stuff */ }.

share|improve this answer
    
Thanks, an oldie but still good to know how to fix :) –  Andrew Oct 9 '12 at 22:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.