Drupal - How to pass Views contextual filter via URL?

Contextual filters aren't passed in separate variables, they are part of the path. If your view path is xxx/yyy then to have a filter value of nn the path would be xxx/yyy/nn.


Use Provide default value in the contextual filter.

contextual filter

also you can use php code for getting the value from url

enter image description here


If you want to pass arguments via GET in the URL you can use BEF module for this.

For example: mydomain.com/your-view-path?field_a=valuea&field_b=valueb

With Better Exposed Filters you need to add exposed filters (not contextual filter), check the expose this filter option and the GET variable name is below in more options. Then if you don't want to show the filter you can hide it in Better Exposed Filters Settings.

Don’t forget to enable Use Ajax option if your view is a block display.

The exposed filter style setting must be set on Better Exposed Filters instead of Basic.

It is very useful with view blocks.

Tags:

Views