WP_QUERY$Gallerypage->提供未定义偏移量的_POST():0

时间:2011-04-05 作者:JM at Work

当我这样做的时候

$gallerypage = new WP_Query(array(
    \'post_type\' => \'post\',
    \'pagename\' => \'gallery\'
));

$gallerypage->the_post();
最后一行$gallerypage->the_post(); 给了我错误。为什么会这样?这似乎是正确的?

Notice: Undefined offset: 0 in /site/url/wp-includes/query.php on line 2719
Notice: Trying to get property of non-object in /site/url/wp-includes/query.php on line 3491
Notice: Trying to get property of non-object in /site/url/wp-includes/query.php on line 3493
Notice: Trying to get property of non-object in /site/url/wp-includes/query.php on line 3495
Notice: Trying to get property of non-object in /site/url/wp-includes/query.php on line 3496
Notice: Trying to get property of non-object in /site/url/wp-includes/query.php on line 3503
Notice: Trying to get property of non-object in /site/url/wp-includes/query.php on line 3514
Notice: Trying to get property of non-object in /site/url/wp-includes/post-template.php on line 30
Notice: Trying to get property of non-object in /site/url/wp-includes/post-template.php on line 30
wp包括/查询。php第2717行之后

$this->current_post++;

$this->post = $this->posts[$this->current_post]; // error here?

1 个回复
最合适的回答,由SO网友:MikeSchinkel 整理而成

你好@JM at Work:

尝试包装$gallerypage->the_post(); 具有if ($gallerypage->have_posts()): ... endif;

应该是这样的:

if ($gallerypage->have_posts()):
  $gallerypage->the_post();
endif; 
请参见:

结束

相关推荐