Whats the difference between post_limits and pre_get_posts?

Note that here you’re overriding the paging of the main query, with the posts_limits filter, by using hardcoded values:

'LIMIT 0, 25'

where 0 is the offset and 25 is the number of posts to display.

So in this case I would just use pre_get_posts with

$query->set( 'posts_per_page', 25 );

and we don’t have to worry about the paging.

If i wanted to return 5 posts conditionally without paginating the
remainder, would i use post_limits or pre_get_posts?

If we later decide that pagination is necessary, then we would need to rework your posts_limits code. The pre_get_posts filter would work as is and we could therefore say that it’s at least a more “future proofed” method.

Another thing: If you were using get_posts() or WP_Query() with suppressed filters, then the posts_limits filter wouldn’t be available while the pre_get_posts hook would be accessible.

Leave a Comment