I have created view to search nodes of video from content type channel. I have set the URL as channel/%/search in view. when redirected to the page the the URL will be channel/all/channel-search?title=test. But I want to replace 'all' with 'nid' which I have got by php code. In short I want to replace channel/all/channel-search?title=test with channel/*NID*/channel-search?title=test (nid may be anything channel/26). I have written the code in views contextual filter but it is not working.

$filter = preg_replace('///','',parse_url($path,PHP_URL_PATH),1);
$path = drupal_lookup_path("source", $filter);
$node = menu_get_object("node", 1, $path);
return $nid;
  • Can i fetch the current url, update it and redirect user to the updated url. IS IT POSSSIBLE??? – D-pak Jun 25 '14 at 9:52
  • How and from where you are redirecting? – wolverine Jun 25 '14 at 11:15
  • I am on sitemap/channel/natural-purity where i got nid of Natural Purity node. Now I am being redirected to the page channel/*NID*/search?title=nature. I have a block on channel/*NID*/search?title=nature which is giving me nid from previous url. How to set that nid to the current page i.e channel/*NID*/search?title=nature ( which should be channel/555/search?title=nature if nid=555). – D-pak Jun 25 '14 at 11:42
  • I am asking, How you are redirecting?. Manually using drupal_goto() or any other manner. – wolverine Jun 25 '14 at 11:53
  • I have used exposed form in block so itself it redirects to the view page from the page on which the exposed form (i.e filter in view) is displayed. – D-pak Jun 25 '14 at 12:03

Instead of doing your way, try out the following

Implement hook_form_alter() and modify the #action attribute of views exposed form.

function mymodule_form_alter(&$form, &$form_state, $form_id){
  $node = menu_get_object("node", 1);
  if(!is_null($node)) {

And then in your view add a contextual filter Content:nid and provide default value as Content ID from URL

Note : The code I tested with frontpage view, so replace the form id with your own.


Add a new contextual filter, select 'Node: Nid', then check 'Provide default value' and in the select box choose 'Content ID from URL'

  • But what I want is, nid should be of previously uploaded node id. The nid from referer url to be passed as contextual filter to the view page which is being viewed. – D-pak Jun 25 '14 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.