0

When I do

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

$gallerypage->the_post();

the last line $gallerypage->the_post(); is giving me errors. Why is that? It seems correct?

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 line 2717 onwards

$this->current_post++;

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

Hi @JM at Work:

Try wrapping $gallerypage->the_post(); with if ($gallerypage->have_posts()): ... endif;

It should look like this:

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

See:

  • Thanks, I was expecting the page to exists so I skipped that for simplicity, but backfired ... I should be searching for a "page" instead of a "post" – JM at Work Apr 5 '11 at 5:28
  • @JM at Work - So my reply answered your question, or not? – MikeSchinkel Apr 5 '11 at 5:36
  • Yes, I forgot to mark it as answer – JM at Work Apr 5 '11 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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