Passing Arguments for a filter to a view (views 3) in code scenario?

Events happening in the community are now at Drupal community events on www.drupal.org.
simonwidjaja's picture

Hi Drupal Friends,
I am working on a Views 3 Project and I'm stuck with this issue:

So far:
A Service-Method that reads a view and returns the results:
$products_result = views_get_view_result($viewName);

Goal:
Now I want to add a filter (default or contextual???) for setting the maximum price (e.g. "maximum price": field_price < max_price)

Problem:
I did setup the filter and it works properly. But I am not able to pass the arguments in code scenario. The documentation says that views_get_view_result(...) can expect additional arguments. But I didn't find any examples for that case. I tried passing the arguments as follows:
views_get_view_result($viewName, NULL, 666 );
views_get_view_result($viewName, NULL, array( 666 ) );
views_get_view_result($viewName, NULL, array( "field_price_value" => 666 ) );
But I wasn't lucky. What am I doing wrong?

I found a workaround. But I'm not really happy with that, 'coz it's a little too dirty:
I can simulate the exposed form filter and set the GET-Parameter via code before I get the view results like this:
$_GET["field_price_value"] = 664;
That works. But I'm sure there is a better way with the Views API.

Thanks in advance!
Simon

Comments

Simon check out

Views Developers

Group organizers

Group notifications

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