What is the right syntax whn you want to embed
http://example.com/mp3list?filter0=75

The documentation says

function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0, $offset = 0, $filters = NULL)
* @param $filters
* An array of exposed filter ops and values to use with the exposed filter system
* Array has the form:
* [0] => array('op' => 'foo', 'value' => 'bar'),
* [1] => array('value' => 'zoo'), // for a locked operator, e.g.

But how do you actually embed a view with filters in it.

i.e. I want to see the view 'mp3list' with filter0 set to 75

I thought about using this code

$view = views_get_view('mp3list');
$view->filter[0]['#value'] = '75';
print views_build_view('embed', $view, $args);

But it doesn't work.

What is the right syntax whn you want to embed
http://example.com/mp3list?filter0=75
?

Comments

merlinofchaos’s picture

Version: 5.x-1.6-beta5 » 5.x-1.6
Status: Active » Fixed

The last argument to views_build_view is the filters:

/**
 * @param $filters
 *   An array of exposed filter ops and values to use with the exposed filter system
 *   Array has the form:
 *     [0] => array('op' => 'foo', 'value' => 'bar'),
 *     [1] => array('value' => 'zoo'), // for a locked operator, e.g.
 *   If no array is passed in, views will look in the $_GET array for potential filters
 */

So, you have to set your filter in that array, and pass that argument.

MauMau’s picture

"So, you have to set your filter in that array, and pass that argument"

I knew that. I just made a zillion errors in the syntax.

For people with my feeble grasp of the syntax, here's what you do in real life:

$view = views_get_view('mp3list');
$filters = views_get_filter_values(array('filter0' => 75, 'filter1'=>47));
print views_build_view('block', $view, $args, false, 0, 0, 0, $filters);

This gives you (more or less)
http://example.com/mp3list?filter0=75&filter1=47

One day, after views 2 is out, I might collaborate with someone smart on writing a usage.txt for views.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

leovarg’s picture

how do you do this with view 6?