posts_distinct_request filter

Filters the DISTINCT clause of the query.

apply_filters_ref_array( 'posts_distinct_request', string $distinct, WP_Query $query )


This is filter hook , its filter the DISTINCT clause of the query.
For use by caching plugins.
Its consists of two parameters, one is $clauses, second is $query.


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

Live Example

To run the hook, copy the example below.

$distinct = apply_filters( 'posts_distinct_request', $distinct, $query ); 
if ( !empty( $distinct ) ) { 
   // everything has led up to this point... 

The following example is for adding a hook callback.

// define the posts_distinct_request callback 
function filter_posts_distinct_request( $distinct, $query  ) { 
    // make filter magic happen here... 
    return $distinct; 
// add the filter 
add_filter( 'posts_distinct_request', 'filter_posts_distinct_request', 10, 1 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'posts_distinct_request', 'filter_posts_distinct_request', 10, 1 ); 

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