Limit query total results

Hello,

I have a loop for CPT, and I want to limit the total results given.

for example I have 7000 results and I want to limit the output to 1000

Im also using grid builder for filters if that helps

Thanks

You can limit the results returned via the ‘posts per page’ option in the query loop

1 Like

I am not sure if that is the solution.

The way I know it, posts_per_page only sets the actual posts per page and not the amount of posts…

Cheers

Patric

* **posts_per_page** (*int*) – number of post to show per page (available since version 2.1, replaced **showposts** parameter). Use ‘posts_per_page’=>-1to show all posts (the’offset’parameter is ignored with a-1` value).

I think this is what you are looking for:

function wpcodex_filter_main_search_post_limits( $limit, $query ) {

// We only want to filter the limit on the front end of the site,
// so we use is_admin() to check that we aren't on the admin side.

	if ( ! is_admin()  ) {
		return 'LIMIT 0, 1000';
	}

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

Source:

1 Like

Awesome Patric

This is the solution, adding this to the theme function worked.

1 Like

@Ultron this limits per page, im looking for the total query limit.