Sorting by linked node/entity reference fields Suppose I am printing name tags for thousands of content nodes in one content type called "Attendee." Each of these nodes specifies a single "Attendee" for an event, (and their respective name tag). Suppose these attendees also needed name tags printed out for their “friends” who are attending with them. That is not a problem: These friends need their own node with the same fields to get their own name tag, so I keep them in the same content type and distinguish that they are a friend of an attendee with a simple checkbox.

When rendering the view, I need these friends of attendees to appear right after the attendee they are going with. So to link them, I used a node reference or a entity reference field. How do I get the Views module to sort the friends of attendees right after the attendee they are going with?

P.S. I am technically using the Views PDF module, but it has the basic views functions, so if it's possible with Views, it will probably be possible with this module.
Since you haven't been able to see the new fields for ordering (which is odd), you will probably have to perform a query alter on the views query and do some modifications:

&lt;?php
function mymodule_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'myviewname') {
    $view-&gt;query-&gt;somecodetoselectfields
    $view-&gt;query-&gt;somecodeforleftjoin
    $view-&gt;query-&gt;orderby[0]['field'] = "FIELDNAME";
    $view-&gt;query-&gt;orderby[0]['direction'] = "ASC";
  }
}
?&gt;


What I usually do is just add a tag on the views query so that I can modify it using the standard Drupal query interface, which is much easier to use IMO.

&lt;?php
function mymodule_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'myviewname') {
    $query-&gt;tag[] = 'mytag';
  }
}
?&gt;


Then

&lt;?php
function mymodule_query_mytag_alter(QueryAlterableInterface $query) {
  $query-&gt;blablabla;
}
?&gt;


Take a look at:

https://www.drupal.org/node/310077
https://api.drupal.org/api/views/views.api.php/function/hook_views_query_alter/7
https://api.drupal.org/api/views/plugins%21views_plugin_query_default.inc/class/views_plugin_query_default/7

Apologies if the solution is not straightforward enough.