Dear all,

I've created a view, and its output is dependant on a taxonomy term ID being passed through the URL. Let's say the view is called 'projects_per_region'. This view will accept the region ID (there is a taxonomy vocabulary defining the different regions) and will ouput the names of the projects linked to that region. The url path is being defined on the view as 'projects/term/%', where % is the argument for the taxonomy term ID (while 'all' being the wildcard), and this is validated against my region taxonomy vocabulary.

So from URL things work fine. If I type 'mysite.com/projects/term/886', I get a list of the projects link to region ID 886 (let's say South India for example).

I now want to embed this view in a template, for it to be called programmatically and then pass the term ID to it in order to get the view. First I retrieve my term ID, this is easy in my particular case:


$nid = $fields['nid']->content;
$node = node_load($nid);
$name = $node->title;
$term = taxonomy_get_term_by_name($name);
$term_id = $term[0]->tid;

Now I want to pass the $term_id as an argument for the view, and get the results, being those the name of the projects related to that taxonomy term id. I'm using the function views_embed_view but I cannot see where to inject the $view arguments there. Any hints??

	print views_embed_view('polygon_taxonomy_term', $display_id = 'block');

Thanks everyone.

Comments

matkeane’s picture

Hi,

I thought I'd seen some detailed docs somewhere, but I can't find the link now. However, I found this comment with the answer from the definitive reference: http://groups.drupal.org/node/17397#comment-59414

Basically, you just tack your argument on in the views_embed_view call so, in your case, something like:

print views_embed_view('polygon_taxonomy_term', 'block_1', $term_id);

Note that the $display_id is the internal Views name for the display, not the name or title that you give it in the UI.

ibagur’s picture

Hi,

Great, this is EXACTLY what I was looking for. Thanks alot!

jukka792’s picture

Hi,

How I can pass taxonomy term ID from url to embedded view?

This works when I write it manually in the code, but I need to get that argument dynamically from the taxanomy term on node?
print views_embed_view('quiz_results_included', 'block', '25');

This does not work:
print views_embed_view('quiz_results_included', 'block', $term_id);

My view has contextual filters as follows:
content:term_name
Content: Has taxonomy term ID depth modifier
Content: Has taxonomy term ID (with depth)

And relationships:
Content: Taxonomy terms on node

so what should I put instead of "$term_id" ?

gouli’s picture

For multiple arguments, you could use something like this 

views_embed_view('tracking_tag_list', 'panel_pane_1', $arg1,$arg2,$arg3);