Split Authors — Verbose
$authors = get_the_author(); // gets the author as a string but doesn't echo, which the_author() does.
if (strpos($authors, ', and ' )) {
$author_list = explode(', ', str_replace(', and ', ', ', $authors));
}
elseif (strpos($authors, ' and ' )) {
$author_list = explode(', ', str_replace(' and ', ', ', $authors));
}
elseif (strpos($authors, ' & ' )) {
$author_list = explode(', ', str_replace(' & ', ', ', $authors));
}
else {
$author_list = explode(', ', $authors);
}
$conjunctions = array(', and ', ' and ', ' & ' );
$author_list = explode(', ', str_replace($conjunctions, ', ', $authors));
Split Authors — Concise
Wordpress Code for the C4LJ site: a concise version which uses the conjunctions array to do a string replace and then explodes it into an array. However there’s some reason why this wasn’t working on the site, so holding onto it here for now.
/*
where our site saves the authors as a string created by a meta field.
and this string is entered as anything from "Ruth Tillman and Becky Yoose" to "Ruth Tillman & Becky Yoose" to "Ruth Tillman, A. Scarlet Galvan, Becky Yoose" and must be parsed
run substitutions so names are all ', ' separated
exploding single name with no separator makes a one-item array
*/
$authors = get_the_author(); // gets the author as a string but doesn't echo, which the_author() does.
$conjunctions = array(', and ', ' and ', ' & ' );
$author_list = explode(', ', str_replace($conjunctions, ', ', $authors));




