I'm using a custom PHP field to get how many days since the last comment on a node. I have a relationship for "Last Comment" set up in the view. I'm using the following PHP code in the custom field:

$comment = strtotime($row->changed_1);
$daysPast = round((time() - $comment)/86400);
echo $daysPast;

This works fine for both the table view and the map as long as I display the Last Comment field; however, when I select: "Exclude from display" on the Last Comment field in the view, it stops working in the map. It still works fine in the table view, but the map view no longer retrieves $row->changed_1 properly to use in the custom PHP field.

Comments

RdeBoer’s picture

Hi Ryan,
Thank you for your report.

Are you using the "value" field in the Views PHP UI or the "output" field?

And which version of Views PHP?

Rik

ryantollefson’s picture

Priority: Normal » Minor

Thanks RdeBoer, you set me on a workaround path...

I was using the Output field.
Views PHP 7.x-2.x-dev - but I think I'm on a build from at several months back.

Playing around with this a bit more, I was able to get it to work by using both the "value" field & the "output" field.

Value field (of course without php markers for the value field):

return round((time() - $row->changed)/86400);

Output field:

echo $value;

This works great for what I need!

Still seems strange that it didn't work the other way (especially when the table view worked just fine). I still think there might be a bug here, but easy enough to work around. I'm fine with closing issue if we want, but it may pop up again for someone.

RdeBoer’s picture

Title: Global PHP field requires token field to be displayed » Global PHP field in combo with "Exclude from display" (workaround)
Status: Active » Needs work

Hi Ryan,
Great that you found and shared your workaround.
Views PHP is a bit of an odd bed fellow for Views, so can may the setup a bit finicky.
I'll mark it as "Needs work" -- but it may be some time before I work on it.
Rik

rcodina’s picture

@ryantollefson Many thanks for sharing your workaround. It worked for me too!