I'm trying to manipulate some fields on Views with Views PHP.
I have a (term) field for author(s). It can have one author or more.
Normally it looks like as that:
Book Title | Author
My First Book | Name1 Surname1, Name2 Middle2 Surname2
My Second Book | Name3 Surname3
etc.
What I want to do is to print names as that:
Book Title | Author
My First Book | Surname1, Name1 - Surname2, Name2 Middle2
My Second Book | Surname3, Name3
In order to do that, I used Global: PHP field with Content: Authors.
Value code inside Global: PHP is that:
$names = $row->field_authors;
foreach ($names as $name) {
$parts = explode(' ', $name);
if (count($parts) == 1) {
$wanted = print($name);
continue;
}
$last = array_pop($parts);
$wanted = print ($last . implode(' ', $parts));
}
return $wanted;
Output code is:
<?php print $value; ?>
But it doesn't return anything. I tried some other similar code but nothing changed.
Is it about the Content: Authors field (multiple field settings etc.) or am I wrong about the code I used in the Global: PHP field?