How to modify query so it grabs only 90 posts in total?

I want to have 3 Pages with 30 posts each: Total 90 posts.
/page/4/ shouldn’t exist. Should either 404 or redirect to home.

Only /, /page/2/ and /page/3/ should exist.
With 30 posts each, like so:

/ posts -> 01-30
/page/2/ posts -> 31-60
/page/3/ posts -> 61-90

I’ve tried numerous suggestions, none limit the query for me. Just the number of posts per page. This looked promising but has no effect (/page/999/ works)

function wpcodex_filter_main_search_post_limits( $limit, $query ) {

if ($query->is_front_page()) {
//this:
return ’90’;
//or even this:
return ‘LIMIT 90’;
}

return $limit;
}
add_filter( ‘post_limits’, ‘wpcodex_filter_main_search_post_limits’, 10, 2 );

Some people as a work around suggest counting with PHP and using an if to stop showing the posts. That’s a work around i want to limit the SQL query.

Read more here:: How to modify query so it grabs only 90 posts in total?

Leave a Reply

Your email address will not be published. Required fields are marked *