Dynamic Date Range Filter

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by ocirs on March 23, 2009 at 12:24am

Hey Guys,

I'm trying to change the date filter for one of my views dynamically so I can output a set of nodes from a fixed time frame depending on the views argument. For example, if the argument date is 2-19-09, I would like the view to display all nodes created between 2-10-09 to 3-10-09. I wrote the script to calculate the min and max date for the view, however, when I try to set those parameters and display the view the date range limit is not applied.

I created a dummy filter under the views admin gui with "Node: Post date between 2000年01月01日 and 2020年01月01日" to encapsulate all nodes

Then I tried to edit that filter dynamically in a custom php block with

$view = views_get_view($view_name) or die('No view available.');

$display_id = "panel_pane_" . $display_id;

$view->set_display($display_id);

$view->display[$display_id]->display_options['filters']['created']['value']['min']=date("Y-m-d",$date_range['start_date']);
$view->display[$display_id]->display_options['filters']['created']['value']['max']=date("Y-m-d",$date_range['end_date']);

$view->is_cacheable = FALSE;

print $view->preview($display_id, array($term_id));

Where $date_range['start_date'] is the min post date of the node and $date_range['end_date'] is the max post date of the node.

Help would be greatly appreciated thanks.

Comments

Date range filter

Posted by fcortez on January 21, 2010 at 9:13am

I'm trying to do a similar function but haven't accomplished it. Did you ever figure it out? It would be of a great help.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /