Created
November 3, 2015 13:59
-
-
Save tommcfarlin/e18ee6cb5ad8ec7bf91e to your computer and use it in GitHub Desktop.
[WordPress] Modifying the WordPress query to select distinct records.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'posts_distinct', 'acme_select_distinct_search_records' ); | |
/** | |
* Adds 'DISTINCT' to the query that's executing on the search page. | |
* | |
* @param string $distinct The initial DISTINCT clause. | |
* @return string $distinct The 'DISTINCT' keyword, if we're on the search template. | |
*/ | |
function acme_select_distinct_search_records( $distinct ) { | |
if ( is_admin() || ! is_search() ) { | |
return $distinct; | |
} | |
return 'DISTINCT'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment