I have a view with a node reference field as contextual filter. Instead of using pagename/[nid] I would like to use /pagename/[title] or the pathauto url.

For uid fields there is an option to either use the uid or the name (or even both). I don't see such an option for nodes.

Is it possible?

2 Answers 2


The reason Views' user reference field allows both the user uid and name is most probably because they are both unique, while the title of a node isn't guaranteed to be so, but of course the nid is.

If, however, your content titles are unique, you might try using it as the contextual filter, hooking it up with a relationship (or rather whatever the D7 term is for it :) to the node reference field, and using all of the lower case transforms and spaces to dashes stuff.

That only leaves a problem if the title has funky characters in it, eg, if the title is This & That your path has to be pagename/this-&-that for the view to work which is ugly to say the least.

Now, how I've dealt with this is to create another text field in my content types that I want to search for by title and I store a url safe title in there. I auto fill them here in D6 land like this:

function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {

  if (isset($node->field_url_safe_title) && $op == 'presave') {
    module_load_include('inc', 'pathauto');

  // all the other nodeapi stuff here


and now I can use pagename/this-that by filtering on this field instead of the title.

I use the nodeformcols module to hide this field on the node edit/add forms and don't display it in the node itself, but I am sure there are D7 ways of doing that. Obviously, in D7, I'd also assume you'd use hook_node_presave() instead of hook_nodeapi() and add in a language array field when setting the field, but the logic would remain the same.

  • 2
    great trick, sounds like a lot of work ;-) What I did for now was just append the title to the url, that way I get the most of the SEO benefit but don't have to do all the work ;-) So the links would look something like /mypath/123/mytitle
    – uwe
    Commented Jul 24, 2012 at 5:04

I had a similar problem and after solving it, I have shared my detailed solution (the drupal way) on a similar question here - How to use node title or path alias instead of node id in node reference contextual filter in views?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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