I have a view that shows related products by means of a contextual filter (PHP). If the returned nid values from the contextual filter is for example "20697, 20735, 20768, 20903, 20695, 21863" I want the nodes to be rendered in that order.
But they don't, I have tried all kinds of settings with no luck. The order given is in fact the delta of a certain field, but when I try to use the delta version of that field as a sort criteria, it is simply ignored, even if I add a relationship under "Advanced".
Anyone who recognizes this behaviour?
EDITED: This is my contextual PHP filter. It fetches all the nid's entered in a certain node reference field as I explained above. And I want them to show in that same order, so that the admin user can sort the order by dragging the rows in the Node reference field:
$node = menu_get_object();
$value = null;
if(empty($node->field_lagg_till_givargrupp['und'][0]['nid'])){
$node->field_lagg_till_givargrupp['und'][0]['nid'] = NULL;
$value = FALSE;
return $value;
} else {
$limit = count($node->field_lagg_till_givargrupp['und']);
for($i = 0; $limit > $i; ++$i){
$group_nid = $node->field_lagg_till_givargrupp['und'][$i]['nid'];
$group_node = node_load($group_nid);
$limit2 = count($group_node->field_koppla_givare['und']);
for($x = 0; $limit2 > $x; ++$x){
$value .= $group_node->field_koppla_givare['und'][$x]['nid'].",";
}
}
return rtrim($value, ",");
}
EDITED: this is the SQL query (I have added a few nids as an example);
SELECT node.nid AS nid, field_data_field_koppla_givare.delta AS field_data_field_koppla_givare_delta, field_data_field_koppla_givare.field_koppla_givare_nid AS field_data_field_koppla_givare_field_koppla_givare_nid, 'node' AS field_data_field_givargrupper_node_entity_type, 'node' AS field_data_field_huvudbild_givare_node_entity_type, 'node' AS field_data_field_tumnagel_givare_node_entity_type, 'node' AS field_data_field_underrubrik_givare_node_entity_type, 'node' AS field_data_body_node_entity_type, 'node' AS field_data_field_artikelnr_produkt_node_entity_type, 'node' AS field_data_field_pris_givare_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_koppla_givare} field_data_field_koppla_givare ON node.nid = field_data_field_koppla_givare.entity_id AND (field_data_field_koppla_givare.entity_type = 'node' AND field_data_field_koppla_givare.deleted = '0')
WHERE (( (node.nid IN('20697', '20735', '20768', '20903', '20695') ) )AND(( (node.status = '1') )))
ORDER BY field_data_field_koppla_givare_field_koppla_givare_nid ASC
And this is the simple query without the delta field and without the order by criteria trying to sort in hook_views_pre_render() instead (see this question about that Sorting logic with anonymous function does not work):
SELECT node.nid AS nid, 'node' AS field_data_field_givargrupper_node_entity_type, 'node' AS field_data_field_huvudbild_givare_node_entity_type, 'node' AS field_data_field_tumnagel_givare_node_entity_type, 'node' AS field_data_field_underrubrik_givare_node_entity_type, 'node' AS field_data_body_node_entity_type, 'node' AS field_data_field_artikelnr_produkt_node_entity_type, 'node' AS field_data_field_pris_givare_node_entity_type
FROM
{node} node
WHERE (( (node.nid IN('20697', '20735', '20768', '20903', '20695') ) )AND(( (node.status = '1') )))
As you can see I am really stuck in all ways about this ...