jmatwork
  • 0
Учитель

WP_Query $gallerypage-> the_post() дает неопределенное смещение: 0

  • 0

Когда я делаю

$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-includes/query.php строка 2717 и далее

$this->current_post++;

$this->post = $this->posts[$this->current_post]; // error here?
Share
  1. Привет @JM на работе:

    Попробуйте обернуть $gallerypage->the_post(); сif ($gallerypage->have_posts()):... endif;

    Это должно выглядеть так:

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

    Видеть:

    • 0

Оставить ответ

You must login to add an answer.