Please could someone kindly advise me on the appropriate way to include a Session Variable as a field and a filter within a view. I want to limit a view to show the records for the current session, stored as $_SESSION['sessionref']. I have tried one or two approaches but without success so far.

Thanks.

Comments

GrahamO’s picture

I have found that this can be done with Views 3 and does not need Views PHP.

In the Advanced Settings add a Contextual Filter, in my case for a field I called 'Order Reference'.

Then for 'when the filter value is not in the URL' provide a default value of type 'PHP Code' and under 'PHP Contextual Filter code' enter 'return' followed by the Session Variable, in my case 'return $_SESSION['shoppingref'];'

Simple when you know how!

mrweiner’s picture

Status: Active » Closed (fixed)