Skip to main content
added 182 characters in body
Source Link
shanebp
  • 5.1k
  • 6
  • 27
  • 40

Are you saying that your dropdown has duplicate authors?

If so, to remove duplicates, try:This is just a basic php array question - not a WP question.

function unique_authors ( $authors ) {
    $newArray = array();

    foreach( $authors as $item ) {
        $itemArray = explode( ", ", $item );
        $newArray = array_merge($newArray, $itemArray);
    }

    $newArray = array_unique($newArray);
    return $newArray;
}

$authors = unique_authors( $authors );

foreach( $authors as $author ):  //etc

https://www.php.net/manual/en/function.array-unique.php

Are you saying that your dropdown has duplicate authors?

If so, to remove duplicates, try:

$authors = array_unique($authors);

foreach( $authors as $author ):  //etc

https://www.php.net/manual/en/function.array-unique.php

This is just a basic php array question - not a WP question.

function unique_authors ( $authors ) {
    $newArray = array();

    foreach( $authors as $item ) {
        $itemArray = explode( ", ", $item );
        $newArray = array_merge($newArray, $itemArray);
    }

    $newArray = array_unique($newArray);
    return $newArray;
}

$authors = unique_authors( $authors );

foreach( $authors as $author ):  //etc
Source Link
shanebp
  • 5.1k
  • 6
  • 27
  • 40

Are you saying that your dropdown has duplicate authors?

If so, to remove duplicates, try:

$authors = array_unique($authors);

foreach( $authors as $author ):  //etc

https://www.php.net/manual/en/function.array-unique.php