I currently have a list of posts with the custom field "Name," with several posts having the same value for "Name."
I would like to retrieve a list of posts that all have unique values for "Name." For example, Post 1 and Post 2 can't both be "Michael."
Is there a way to do this by altering the SQL query directly, before it's executed? I am currently using the function below (limit 5 posts and ordered randomly) to alter the query.
function alter_the_query( $request ) {
$dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars
$dummy_query->parse_query( $request );
if ($dummy_query->is_category()) {
$request['posts_per_page'] = 5;
$request['orderby'] = 'rand';
}
return $request;
}
I am trying to avoid using SQL directly for sake of compatibility with future versions of Wordpress, but if that's the only way then I'm still open to those suggestions.