I use the Views PHP field to retrieve a numeric value from database, but it could not be sorted even after i have checked the Enable click sort and select Sort numerically.
It will throws an error.
It can be fixed by selecting Sort using custom PHP code with the following code.
return $row1->php - $row2->php;
Done =)
Reference: Views PHP sort snippet does not work
Nice post! Looks simple but I couldn’t get it to work 😦
LikeLike
What problem did u meet?
LikeLike
Hi,
I’ve a view which displays users posts related to specific nodes (suppose comments to nodes), when showing comments I want to show comments of author first and then sort other comments in ascending order. To achieve this I’ve added a PHP field which return integer i.e. if current comment author is same as node author then -1, else comment author.
I’ve followed the instruction in your post but its not working.
Have you added any filters to sort with?
Have you added “value code” in your Global: PHP field
LikeLike
Hi,
Thanks, got it working, here is Drupal.org issue link for solution I’ve refered to:
http://drupal.org/node/1178170#comment-6032566
LikeLike
Good to know that you have found the solution. =)
LikeLike
Wow .. working like a charm !
LikeLike
good to know that it helps. =)
LikeLike
Thank you for this code – it works fine. 🙂
LikeLike
Thanks for your comment too. =)
LikeLike
Thanks for the code! Anyone know how to sort within this sort. For example sort numerically with Global PHP, then alphabetically on another field?
LikeLike
The views sorting feature is only for one column sort. if you want to sort by multiple columns, you could try using other module like tablesorter. Or you have to write a custom module as described here.
Reference: StackOverflow – Double View Table Sort by two columns
LikeLike