Ниже я привел пример того, что вы можете сделать.
Я не могу дать вам точное исправление, потому что я не знаю, что содержит ваш класс WP_Query
, но мой пример ниже должен дать вам понимание того, что вам нужно сделать, чтобы достичь того, что вы хотите.
// Set empty array that we will populate with authors.
$exists = [];
// Example list of authors.
$authors = ['Bob', 'Kirsty', 'Ralph', 'Penny', 'Kirsty', 'Bob', 'Alfie'];
// Loop through each author.
foreach($authors as $k => $author) {
// We check to see if this author has already been mentioned, if it has, skip it.
if(in_array($author, $exists)) continue;
// Author has not previously been mentioned, so we echo this statement.
echo 'The author for this iteration is ' . $author . '.<br />';
// As this author hasn't been mentioned before, put them in the '$exists' array.
$exists[] = $author;
}