Limit WP_Query to only X results (total, not per page)

As you already mentioned, to limit the number of posts retrieved by the query, you can use posts_per_page.

This argument works both for get_posts and WP_Query(), for example:

$args = array(
    'posts_per_page' => 5,

);
$posts_array = get_posts( $args );

And as stated in the link you provided, no_found_rows = true will end the query after it reached its criteria. It’s totally optional, and not very common.

Leave a Comment