Skip to content

Instantly share code, notes, and snippets.

@ruthtillman
Last active July 7, 2019 22:06
Show Gist options
  • Save ruthtillman/66a5c9c50160adc1c4387f89e0814937 to your computer and use it in GitHub Desktop.
Save ruthtillman/66a5c9c50160adc1c4387f89e0814937 to your computer and use it in GitHub Desktop.
Parse authors C4LJ Wordpress
<?php
/*
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));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment