Drupal 7. In a node/edit form panel I have added a view that returns nodes. I whish to filter thoses nodes and keep only the nodes whose nid is less than the nid of the node beeing edited.
the url of the node/edit form is : /node/11541/edit?step=11538
the nid of the node being edited is : 11541
I wish the view to return only the nodes whose nid < 11541
I use Views PHP
I have followed Adrian's code : I use the CONTEXTUAL FILTER with a condition on "equal to nid", and I alter the condition to relace "equal to" by "< to" .
it works when I do it for only one view on my page. For the second view :) (same view but with a different condition , it doesn't work. Below is my code. is it possible that the function cannot handle twice the query variable ?
`function fdrav_views_query_alter(&$view, &$query) {
if($view->name == 'metier2') {
/* Using the following line dmp($query)
* (you need the devel module to use dpm) you will be able to search
* where is condition to alter, you will see that in the
* $query->where[0]['conditions'][]['field'] you will have:
* node.nid = :node_nid
* so your solution will be replace the
* = operator by the < operator
* at this moment you can't do this from the Views UI
*/
dpm($query);
$query->where[0]['conditions'][1]['field'] = str_replace('=', '>', $query->where[0]['conditions'][1]['field']);
}
if($view->name == 'metier3') {
$query->where[0]['conditions'][1]['field'] = str_replace('=', '<', $query->where[0]['conditions'][1]['field']);
}
}