Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I'm on archives pages I am using the code below to query posts. In my theme options to_count_home calls the number of posts.

WordPress isn't generating the correct number of pages based on posts_per_page. Instead it is generating pages based on the number of posts per page I have selected in my default WordPress settings. For example, if I have 10 posts per page in the settings then set posts_per_page in the code as 5, when I go to the second page (which should have 5 posts on it) I get a 404 error.

Here is the code I'm using:

<?php
$per_page = get_option('to_count_home');
query_posts("posts_per_page={$per_page}");
if (have_posts())
?>
share|improve this question

1 Answer

up vote 0 down vote accepted

You are not modifying your query, but nuking it completely. Please see query_posts() documentation in Codex on how to correctly re-run query with changed arguments.

share|improve this answer

Your Answer

 
discard

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.