Title: post_limits
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters_ref_array( ‘post_limits’, string $limits, WP_Query $query )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#wp--skip-link--target)

Filters the LIMIT clause of the query.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#parameters)󠁿

 `$limits`string

The LIMIT clause of the query.

`$query`[WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)

The [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/) instance(
passed by reference).

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#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](https://developer.wordpress.org/reference/hooks/pre_get_posts/).

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#source)󠁿

    ```php
    $limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-query.php#L2987)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-query.php#L2987-L2987)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Query::get_posts()](https://developer.wordpress.org/reference/classes/wp_query/get_posts/)`wp-includes/class-wp-query.php` |

Retrieves an array of posts based on query variables.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/post_limits/?output_format=md#comment-content-4765)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/post_limits/#comment-4765)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_limits%2F%23comment-4765)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_limits%2F%23comment-4765)
 4. Example migrated from Codex:
 5. The example below allows your query to return 25 results only for the search page.
    All other queries will continue to return the default value.
 6.     ```php
        /**
         * Limit the main query search results to 25.
         *
         * 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.
         *
         * We also only want to filter the main query, so we check that this query is
         * the main query with $this->is_main_query().
         *
         * Finally, we only want to change the limit for searches, so we check that
         * this query is a search with $this->is_search().
         *
         * @see https://developer.wordpress.org/reference/hooks/post_limits/
         * 
         * @param string $limit The 'LIMIT' clause for the query.
         * @param object $this The current query object.
         *
         * @return string The filtered LIMIT.
         */
        function wpcodex_filter_main_search_post_limits( $limit, $this ) {
    
        	if ( ! is_admin() && $this->is_main_query() && $this->is_search() ) {
        		return 'LIMIT 0, 25';
        	}
    
        	return $limit;
        }
        add_filter( 'post_limits', 'wpcodex_filter_main_search_post_limits', 10, 2 );
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_limits%2F%3Freplytocom%3D4765%23feedback-editor-4765)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_limits%2F)
before being able to contribute a note or feedback.