I have a view of users with a contextual filter for username which works great for whole usernames, but I need to allow this to work with partial names, or specifically whole words (userames are full names with spaces in this case), so if someone search for 'David' it will list all the 'David's, regardless of their surname.

Any help?

EDIT: a bit more googling revealed this, which was able to solve my problem: http://n00bsys0p.co.uk/blog/2012/08/21/drupal-views-3-contextual-filter

2 Answers 2


You can achieve it by many way...make a relation with content:author and you will get all available options under user like (User: Name, User: First Name,User: last Name,User: Authentication name, User: Authmap ID, ) under contextual filter.

  • Sorry - it's a view of users, not content
    – Chris
    Commented Nov 13, 2013 at 6:08

ok, then you can use views_query_alter to make a relation

function mymodule_views_query_alter(&$view, &$query) 
if ($view->name == 'your_view_name') 
  //dpm($query, __FUNCTION__);
   //dpm($view, __FUNCTION__);
   global $user;
   $tid =$user->mail;
   $join = new views_join;
   $join->construct('table_name', 'node', 'nid', 'nid', array(), 'LEFT');
   $query->add_relationship('table_name', $join, 'node');
   // $view->query->set_group_operator('OR');
   //$query->add_where('table_name', 'table_name.field_name',$tid);
   //dpm($query, __FUNCTION__);

i am putting the comment line for the where condition and group before applying this you please enable the "Show the SQL query" from view setting.

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.