I'm currently building a theme for a client, and one of their requirements is endless scrolling on a "Charts" page. They want this to be paginated, and the endless scroll to load the next page below the first, displaying the most popular 40 tracks posted on the site.
To achieve this, I used a new WP_Query, which is running inside a custom page template. The endless scroll works by fetching the next page, and ending when it hits a 404. The problem is, extra pages continue to be loaded, even when there are no posts to display. The script never hits a 404 so it continues to load.
Here is my query:
<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('posts_per_page=8&meta_key=_count-views_all&orderby=meta_value_num&order=DESC'.'&paged='.$paged); $count = 1; while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <div class="count"><?php echo $count; ?></div> //loop here <?php $count++; endwhile; ?> <?php content_nav( 'nav-below' ); ?> <?php else : ?> <?php get_template_part( 'no-results' ); ?> <?php endif; ?> <?php $wp_query = null; $wp_query = $temp;?>
The exact same query works without any issue on the index page and archive pages. It only seems to happen when its in a page template.
I've been stumped by this for the last day or so, and I'm not sure as to why it's happening. Any ideas would be greatly appreciated :)