WordPress query creates infinite loop

I’m following this http://jasonskinner.me/2013/04/creating-a-filterable-wordpress-photo-gallery/ to create gallery.

Unfortunately, it creates infinite loop in the front end.

This is the part in front end template.

<div class="content">
  <ul class="photogal">

    //setup new WP_Query
    $wp_query = new WP_Query( 
        'posts_per_page'  =>  -1,
        'post_type'     =>  'gallery'

    //begine loop
    // while ($wp_query->have_posts()) : $wp_query->the_post();
    if (have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); 

  <li class="element <?php if( function_exists('jss_taxonomy_name')){ jss_taxonomy_name(); }?>">
          <a class="fancybox" rel="<?php if( function_exists('jss_taxonomy_name')){ jss_taxonomy_name(); }?>" 
              //get post thumbnail id
              $image_id = get_post_thumbnail_id(); 
              //go get image attributes [0] => url, [1] => width, [2] => height
              $image_url = wp_get_attachment_image_src($image_id,'', true); 
              //echo out the url
              echo $image_url[0];  ?>
        <?php the_post_thumbnail('album-grid'); //display custom thumbnail size ?>
    </li><!--end li-->

<?php endwhile; // end of the loop.
</ul><!--end photogallery-->

</div><!--end content-->

Read more here: WordPress query creates infinite loop

Leave a Reply

Your email address will not be published. Required fields are marked *