WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

No idea why but pagination on my homepage isn't working although it works in every other place..custom templates, archive, searches. I've tried every version of pagination possible it seems. I've used wp_query, query_posts, get_posts.

I've tried the method of setting temp wp_query and wp_query to null and then adding it again after the pagination.

I've tried just setting paged to $paged. The odd thing to me is the same loops works on an older theme I have but not on mine. It works on a page I've created using the exact same loop. So I'm looking for some hints on what might be causing this. Here is my loop.

 global $wp_query;
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 $args = array(
    'meta_key' => 'rating',
    'meta_value' => 0,
    'meta_compare' => '>',
    'orderby' => 'meta_value_num',
    'order' => 'DESC',
    'cat' => -1,
    'posts_per_page' => 16, 
    'paged' => $paged,
    'post_type' => array( 'post','videos','articles'  )
$wp_query = new WP_Query($args);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
  get_template_part( 'loop', 'contents' );
<div class="infinitescroll">
  <?php next_posts_link('next posts'); ?>

I've tried setting global $paged. I've tried setting the get_query_var to page instead of paged. No dice.

share|improve this question
Can you add the code that creates the pagination text? Or are you having trouble with the next_posts_link and infinite scrolling? – guiniveretoo Nov 5 '12 at 15:38
Right there's no pagination text. Im only using next_posts to get a link for infinite scroll. But I'm testing for mysite.com/page/2 which returns a 404 every way I try. – Pollux Khafra Nov 5 '12 at 16:00
use pre_get_posts to modify the main query before the template and you won't even have to think about pagination- it will just work. – Milo Nov 5 '12 at 16:09
also try mysite.com/paged/2 - you're checking for the paged variable on line 2 above, not page. That's tripped me up more than once. – guiniveretoo Nov 5 '12 at 19:54
Thanks Milo! Fixed. – Pollux Khafra Nov 6 '12 at 10:13
up vote 0 down vote accepted

Using Milo's suggestion in the comments above fixed the issue. Using pre_get_posts we modify the loop like so.

function filter_main_query( $query ) {

    if( is_front_page() && is_main_query() ) {

        $query->set('meta_key', 'rating');
        $query->set('meta_value', 0 );
            // rest of params


add_action('pre_get_posts', 'filter_main_query', 9999);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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