1

I have a view that display content on the site. I have the following hidden filters on it:

Published: Yes
Posted Date: Relative 'today'

Then I want to add a second Posted Date filter but expose it for a user to enter their own custom dates Is between Start date and End date. I then want the view to ignore the hidden exposed filter that is set to 'today' and use the user defined dates.

EDIT:

The default one is a relative date format and the exposed one is to be a jquery date popup.

Thoughts?

1
+50

the question, 'allow an exposed filter to override another filter in Views?" is answered by using filter groups in which you are able to say this filter OR that filter quite easily with Views UI. Check out part 15 of Learn Views with NodeOne (5 min). You will need to great two groups, one for each filter, and then you can order them for OR.

The the two filters are pretty straight forward too. A single one with your relative "today" and a grouped one with your less than and greater than operators and fixed rather than relative time. The Views UI is slick for this too so I wont suck up space with step by step.

As for the jquery date selector, I believe an exposed filter with Date Views and Date Popup installed your "magically" taken care of.

  • Tom, can yuo expand on this as it seems that my attempt is not working. My view is still using the relative date and if I want to override it with dates that have happended prior to "today" it doesn't work. If you can do this I can award you the bounty. – Nigel Waters Jun 7 '13 at 3:14
  • Im looking at three different parts, but assume it is the filter groups causing problems? Edited my answer with a link to a 5 min vid on views filter groups. – Tom Jun 7 '13 at 7:23
  • wow. it really is that easy. I must have done something wrong the first time I tried this.No need to custom coding when this is built into views directly – Nigel Waters Jun 8 '13 at 4:05
  • 1
    @Tom do you have any idea, how to do this in D6. – Bala Jun 10 '13 at 10:59
1

You can modify the view paramteres implementing hooks_views_pre_build. There you can examine received data (for example, checking $_GET) and modify view filters, deleting the "Posted Date: Relative 'today'"filter.

function mymodule_views_pre_build(&$view) {
  if ($view->name == 'my-view') {
    if (must_delete_filter()) {
      unset($view->filter['posted_date_relative_filter_name']);      
    }
  }
}

So Views is executed without that filter. In example code must_delete_filter is the function that decides if filter must be deleted or no.

  • Is it possible without custom module – Bala Jun 4 '13 at 8:31
  • I see that under filters I can add groups and use and/or. Can I use this in some way to get hat I need without resorting to custom coding? – Nigel Waters Jun 4 '13 at 16:11
  • 1
    Well, I don't understand perfectly the logic you want to achieve, so I've explanied a general way to deal with filter changes programatically. Depending on your logic you may get what you want playing with Views interface. Anyway take into account that writing a simple module is easy, you can do a lot of things easier than UI (others are of course easier with UI) and you will level up your Drupal skill ;) – sanzante Jun 5 '13 at 10:44
1

How about not using a hidden filter for the date. If you you expose that filter and give it a default of 'Today', then the user can override the default or keep it as is. Thus, there is no need for multiple filters.

  • because the default one is a relative date format and the exposed one is to be a jquery date popup. – Nigel Waters Jun 4 '13 at 20:56
0

It is possible to create custom module which will add new filter to a view. Have a look a hook_views_api(), then use hook_views_handlers() to register custom view handler, use hook_views_data() - to create a filter and show it in views and finally create a class that extends views_handler_filter(). Looks complex but it isn't. I've implemented date ranges using this technique (for nodes created today, yesterday, last week, last month) but it will work for anything ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.