Hi

I want to pass a node ID into my View via the URL then execute some aribtrary PHP to filter the results to a set of nodes that are related to my node.

However I can't see how to provide a filter value via the URL and then execute PHP.

Am I coming at this from the wrong direction ?

Thanks

Comments

The id in the url can be

The id in the url can be accessed directly in a views php field by using the arg() function.
Just set the parameter of arg to the part of the url containing the ID you'd like processed with php. For example, if you'd like the nid from yoursite.com/node/2 simply use arg(1) to retrieve it.

Thanks. I'm already using

Thanks. I'm already using Views PHP and I'm sure I've done that before, but it completely eluded me.

The problem with this kind of of filter I now realise is that ( in my specific case ) it needs to load an arbitrary number of nodes and doing this for each row feels bad++ !

I want to use Views to output

I want to use Views to output my data because it does such a great job ( sortbale headers etc etc ). But I want to decide which nodes are included in the View based upon my PHP code using a nid passed as a parameter in the url. However this seems to be Catch-22. Because I have provided an argument in the URL Views won't let me execute PHP, as it only provides this functionality when it provides a default value.

I suppose I could execute the code up front when generating the link and pass a list of nids in the url e.g. my-view-path/1+333+26 etc. but this feels wrong.

Any ideas ?

I may have some ideas, but

I may have some ideas, but I'll need to know a bit more about the context you're using it in. How are these nodes related to each other, and are they the same content type or different? It may be possible to use Views PHP to identify the additional nodes based on the NID parameter and add them to the view.

Thanks for your interest

Thanks for your interest bnjmnm.

The nodes are a sequence of a single content type each representing a version of a document. They form a linked list with each instance having an entity reference field to its predecessor version ( if any ) and its successor ( if any ). I want to pass Views a node ID of any of the related nodes and then have Views output a list of all the related nodes.

Any more input appreciated. At the moment my best attempt is to do the work upfront when gernating the link to the view and use mulitple values e.g. mydomain.com/myview/1,6,12,18 ( ie. work out the related nids beforehand and feed them to views via the URL ). However I somehow feel this is cheating !

Cheers

This is something that you

This is something that you could do with a views PHP field. This sample code shows how you would pull earlier drafts and print the title, it's not precisely what you're aiming to do, but the principle can be applied to later drafts as well. If extrapolating what you need is not possible with the sample code, let me know where you are stuck

//from nid of the view url
$rootnode = node_load($row->nid);
//load node from referenced earlier draft
$earlierNode = node_load($rootNode->earlier_draft_id['und']['0']['value']);
        //keep looping while earlier drafts exist
while(isset($earlierNode->earlier_draft_id['und']['0']['value'])){
      print $earlierNode->title
      $earlierNode = node_load($earlierNode->earlier_draft_id['und']['0']['value']);
      
}
//print the title of the earliest draft
print earlierNode->title;