Hi,

I have a (maybe) wierd question. I have a view (as a page), and I have contextual filters (for different taxonomies). It works with http://domain.nu/page/taxonomy/

However, I need it to work like http://domain.nu/page/?query=taxonomy
Why I need this is a completely other discussion, so please don't mind that here. Is it possible? How?

Thanks!

Comments

sasingh’s picture

Today i ran into the similar problem .I solved this problem doing following :
> For the contextual filter ,choose following settings
>>For section 'WHEN FILTER VALUE IS NOT AVAILABLE' select following :
a)tick 'Provide Default Value'
b)select Type = PHP Code
c) in the input box (opens as soon as Type =PHP Code is selected) write following code :

 $query= $_GET['query'];
                      return $query;

Please note that View preview may not show you the view result but on actual link on your site you would see the expected results.

Hope this helps.

Zahak’s picture

That kind of creates other issues when there really are no values (then it's supposed to show all, without any filters at all). Also, I generally really don't like the idea of being able to store php code that way as that is a huge security risk.

janvonmulert’s picture

For anyone else who has this problem, this worked for me:

 if(isset($_GET['query'])){ $query= $_GET['query'];}
 else {$query = 'all';}
 return $query;
dawehner’s picture

Status: Active » Fixed

In general these default value php code can ALWAYS replaced by a custom argument default plugin,
which I guess there are blog posts out there how to write one.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

robinvdvleuten’s picture

For anyone reading this topic, I released a module for this kind of functionality: https://drupal.org/project/views_contextual_filter_query

dddbbb’s picture

Issue summary: View changes

@robinvdvleuten Thanks for the module. Just used it and it works great.

pratip.ghosh’s picture

#3 works great... Thanks :D

cvillian098’s picture

Helped alot thanks

lunk rat’s picture

FYI views in D8 core provides this out of the box.