posts_clauses_request filter

Filters all query clauses at once, for convenience.

apply_filters_ref_array( 'posts_clauses_request', string[] $clauses, WP_Query $query )

Description

This is filter hook , its filter all query clauses at once, for convenience.
For use by caching plugins and its covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, fields (SELECT), and LIMIT clauses.
Its consists of two parameters, one is $clauses, second is $query.

Parameters

  • $clauses : (string[]) Associative array of the clauses for the query.
    ‘where’
    (string) The WHERE clause of the query.
    ‘groupby’
    (string) The GROUP BY clause of the query.
    ‘join’
    (string) The JOIN clause of the query.
    ‘orderby’
    (string) The ORDER BY clause of the query.
    ‘distinct’
    (string) The DISTINCT clause of the query.
    ‘fields’
    (string) The SELECT clause of the query.
    ‘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.

$posts_clauses_request = apply_filters( 'posts_clauses_request', $clauses, $query );                        
if ( !empty( $posts_clauses_request ) ) {                      
  // everything has led up to this point...                         
}   
// define the posts_clauses_request callback 
function filter_posts_clauses_request( $clauses, $query ) { 
    // make filter magic happen here... 
    return $clauses; 
};       
// add the filter 
add_filter( 'posts_clauses_request', 'filter_posts_clauses_request', 10, 1 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'posts_clauses_request', 'filter_posts_clauses_request', 10, 1 ); 
JOIN 100,000+ SUBSCRIBER's FAMILY

 Subscribe to our weekly newsletter below and never miss the latest updates in WordPress