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.

I use the wp for membership site. I use pages for the user log in, manage post, edit profile and etc.

When I apply the default permalink structure, I found that the debug mode show this notice on every pages (not post page).

Notice: Undefined property: WP_Query::$post in /var/www/example/wp-includes/query.php on line 2986 Notice: Trying to get property of non-object in /var/www/example/wp-includes/query.php on line 3349 

But when I use the post name for the permalink structure, this notice disappeared.

Though it seems is not a serious issue (is it?), but I'd to know what causing this warning?

Thanks

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Finally I found what causing this problem, turns out it have to do with my pre_get_post hook. Because I using is_page to check the specific page, which is not appropriate.

Here is what I did

function check_page($wp_query){
   if($wp_query->is_page(array('1','2','3')) ){
           //do something here
     }
  return $wp_query;
}
add_action( 'pre_get_posts', 'check_page' );

So my solution to this is:

 function check_page($wp_query){
    $pageidarray = array('1','2','3');
   if($wp_query->is_page() && in_array($wp_query->query_vars['page_id'], $pageidarray) ){
           //do something here
     }
  return $wp_query;
}
add_action( 'pre_get_posts', 'check_page' );

Problem solved.

share|improve this answer
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.