Drupal views contextual filter: use last argument as filter value I would like a views contextual filter to only use the last argument in the url.    Given the following taxonomy structure, I would want /term-a to return Term A1 and Term A2 only (which works fine).  However, if the url is /term-a/term-a1 I would want only Term A1a to be returned, which isn't working, it's still returning Term A1 and Term A2  

Within views, I don't see a way to use the last part of the path for the filter.  I tried to remove the argument from the path and then use the following as a default argument:

$path = arg();
return array_pop($path);


Here is the sample term hierarchy:

- Term A
  - Term A1
    - Term A1a
  - Term A2
- Term B
  - Term B1
  - Term B2


Just to reiterate what is returned:

The path /term-a returns:


Term A1
Term A2


The path term-a/term-a1 returns:


Term A1
Term A2


The path /term-a1 returns:


Term A1a
One solution would be hook_views_pre_view()

function MYMODULE_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
    if ($view-&gt;name == 'view_machine_name' &amp;&amp; $display_id == 'my_display_id') {
        $args = array(end($args));
    }
}


For a view with one contextual filter this would always set the argument to the last argument from the URL.