2

I created a view with 3 filters. I embedded the view in my tpl.php file for the content type. My question is, how can I set some filter with the value from a CCK field?

This is the code I use:

$view = views_get_view('view_name');
$view->set_display('default');
$view->filters[2]['value'] = $node->field_name[0]['value'];
if (!empty($view)) {
    print $view->execute_display($display_id , $view_args);
}
1
  • Can I get a certain set of rows using an argument instead of a filter? Is there any way to pass the argument programmatically?
    – sergio
    Commented May 28, 2011 at 21:34

2 Answers 2

2

You should use arguments instead of filters on your view. That way you can use views_embed_view.

Just add an argument to the view with the same field you would use as a filter. That adds a where condition to the views query in a similar way as a filter would do.

Then pass on the CCK field value as the third argument on your template file like this:

print views_embed_view('view_name', 'default', $node->field_name[0]['value']);
1
  • what if I want to pass two values for the same argument, e.g. tid[]=1&tid[]=2?
    – Orion
    Commented Aug 14, 2013 at 18:34
0

you could always use like this:

views_embed_view($name, $display_id = 'default', 'your first arg', 'second arg', 'so on', 'so forth');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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