post_limits WordPress Filter Hook

The post_limits WordPress hook is used to set the maximum number of posts that can be returned by a query. This can be useful for limiting the number of posts that are displayed on a page, or for ensuring that only a certain number of posts are returned by a search query.

apply_filters_ref_array( 'post_limits', string $limits, WP_Query $query ) #

Filters the LIMIT clause of the query.


Parameters

$limits

(string)The LIMIT clause of the query.

$query

(WP_Query)The WP_Query instance (passed by reference).


Top ↑

More Information

  • This filter applies to the LIMIT clause of the query before the query is sent to the database, allowing you to define a new query LIMIT.
  • You can return null to remove the LIMIT clause from the query, allowing you to return all results. However, this will set $wp_query->found_posts to 0.
  • On some server environments, the LIMIT will be applied to all queries on the page. This results in menu items and widgets also being limited to the defined number. To only limit the number of posts on a page use the action hook pre_get_posts.

Top ↑

Source

File: wp-includes/class-wp-query.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More