Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Sep 25 '12 at 22:45

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers 3

up vote 0 down vote accepted

Instead of using the_posts filter, you should try pre_get_posts action.

share|improve this answer
    
I managed to get things working using pre_get_posts. Thank you! –  Karolis Sep 26 '12 at 9:18
add comment

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:

global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'post_type' => 'product' ) );
query_posts( $args );
share|improve this answer
add comment

use this plugin

WP-Paginate is a simple and flexible pagination plugin which provides users with better navigation on your WordPress site

wp-pagination

share|improve this answer
add comment

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.