I am using the_posts action to filter out some unwanted posts – this works fine, but the pagination after this is applied gets broken. If for example there is a page with 10 results before the_posts is applied, then after it gets applied the page displays only 6 posts for example, yet there is 100 posts in total and 20 of them should be excluded.
Pagination shows 1-10 pages when it should show 1-8.
So the question is – how to make pagination work as expected and display 10 posts per page and not to have pages with less than that.
Instead of using
the_posts
filter, you should trypre_get_posts
action.Instead of filtering posts inside the loop, you should try filtering them right after the loop. Query_posts() can solve the problem: http://codex.wordpress.org/Function_Reference/query_posts
This is how you can “merge” the modifications on the main query to insert any filters without messing the pagination:
use this plugin
WP-Paginate is a simple and flexible pagination plugin which provides users with better navigation on your WordPress site
wp-pagination