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

I have a list of posts from a category as seen here in this example. The problem is, if you scroll down to the bottom and click older, you'll see that the posts on the page have not changed at all, how ever the url has changed.

Can some one tell me whats wrong with the following code that generate this?

function category_query($query){
    if(is_admin || !$query->is_main_query()){

        $cat_id = get_cat_ID( single_cat_title(null, false) );
        $query->set("cat=$cat_id&posts_per_page=10" );


$attr = array(
    'align' => 'left',
    'class' => 'thumbnail imageRight',
    'width' => 350,
    'height' => 350
    while(have_posts()): the_post();
    <div class="post"><?php
        the_post_thumbnail('medium', $attr); ?>
        <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <p><?php the_excerpt(); ?></p>

    <ul class="pager paddingBottom20">
      <li class="previous">
        <?php next_posts_link('&laquo; Older Entries'); ?>
      <li class="next">
        <?php previous_posts_link('Newer Entries &raquo;'); ?>
share|improve this question
up vote 0 down vote accepted

Don't use query_posts in the template. If you delete that line, your template will paginate correctly.

If you want to alter the main query, use the pre_get_posts action.

Currently, your query overwrites the default main query, and you don't set any pagination parameters within the query, so you're always going to get the first 10 posts.

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.