Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/posts distinct

This page redirects to an external site: https://developer.wordpress.org/reference/hooks/posts_distinct/

Description

The filter eliminates duplicates in your search results.

Usage

The following example shows how to use the filter in a plugin:

function search_distinct() {
	return "DISTINCT";
}
add_filter('posts_distinct', 'search_distinct');

If you return an empty string from the filter, duplicates will continue to show. For example:

function search_distinct() {
	if ( $this->allow_duplicates )
		return ""; // filter has no effect
	return "DISTINCT";
}
add_filter('posts_distinct', 'search_distinct');

Notes

Returning "DISTINCTROW" from the filter has the same effect on the query as "DISTINCT".

This page is marked as incomplete. You can help Codex by expanding it.