WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] WP_Query says "Call to a member function have_posts() on a non-object"

[Resolved] WP_Query says "Call to a member function have_posts() on a non-object"

  • nddery
    Member

    @nddery

    Hi,

    I have this weird error when trying to make a simple WP_Query. Maybe there is something evident that I am missing but I can’t see it.. Here is my code, it is all there is in the page, beside header.php and footer.php obviously..

    // Black Boxes (there is 2)
      $pages = new WP_Query(
        array(
          'post_type' => 'page',
          'post__in'  => array( 23, 21 )
        )
      );
    
      if ( ! $pages->have_posts() ) :
      endif;
    
      while( $pages->have_posts() ) : $pages->the_post();
        the_title();
      endwhile;
    
      // Prevent weirdness
      wp_reset_query();

    Thanks!

Viewing 1 replies (of 1 total)
  • nddery
    Member

    @nddery

    Answered myself here, having named my variable $pages was in conflict with something else here. Named it something else and all is fine now..

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] WP_Query says "Call to a member function have_posts() on a non-object"’ is closed to new replies.