WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. nddery
    Member
    Posted 1 year ago #

    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!

  2. nddery
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic