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

How to use posts_distinct_request filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
August 12, 2022
5 minutes read

posts_distinct_request filter

Filters the DISTINCT clause of the query.

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

Description

This is a filter hook that filters the DISTINCT clause of the query. It’s especially useful for caching plugins. It consists of two parameters: $distinct and $query.

Parameters

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

Live Examples

Basic Usage

To run the hook, copy the example below:

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

Adding a Hook Callback

The following example is for adding a hook callback:

// Define the weplugins_posts_distinct_request callback 
function weplugins_filter_posts_distinct_request( $distinct, $query  ) { 
    // Make filter magic happen here... 
    return $distinct; 
}; 
         
// Add the filter 
add_filter( 'weplugins_posts_distinct_request', 'weplugins_filter_posts_distinct_request', 10, 1 ); 

Removing a Hook Callback

To remove a hook callback, use the example below:

// Remove the filter 
remove_filter( 'weplugins_posts_distinct_request', 'weplugins_filter_posts_distinct_request', 10, 1 ); 

Access Premium WordPress Plugins

Contact Us

Need customization? Contact Us

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.