Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_limits_request filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 6, 2022
5 minutes read

post_limits_request filter

Filters the LIMIT clause of the query.

apply_filters_ref_array( 'post_limits_request', string $limits, WP_Query $query )
  

Description

This hook is used for caching plugins. However 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.

Parameters

  • $limits : (string) The LIMIT clause of the query.
  • $query : (WP_Query) The WP_Query instance (passed by reference).

Live Example

To run the hook, copy the example below.

$array = apply_filters( 'post_limits_request', $array); 
                         
if ( !empty( $array ) ) { 
                         
   // everything has led up to this point... 
                         
} 

  

The following example is for adding a hook callback.

add_filter( 'post_limits_request', 'wp_post_limits_request_filter', 10, 2 );

/**
 * Function for `post_limits_request` filter-hook.
 * 
 * @param string   $limits The LIMIT clause of the query.
 * @param WP_Query $query  The WP_Query instance (passed by reference).
 *
 * @return string
 */
function wp_post_limits_request_filter( $limits, $query ){

	// filter...
	return $limits;
}


To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'post_limits_request', 'filter_post_date_column_time', 10, 4 ); 

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.