I want to output the views block of collection_products which is filtered by a taxonomy term but it doesn't print anything when I tried the following code:

print views_embed_view('collection_products','block_1','sample-category-1');

attached is the views editing page. views editing page So what might be the problem?

  • 1
    Are you sure that sample-category-1 is the correct parameter? Depending on how you set everything up, it might be expecting a taxonomy id or something else instead? Is the contextual filter configured to hide results if nothing matches, change it to display all data, see what happens then. That allows you to discover what is wrong. – Neograph734 Oct 8 '17 at 15:41
  • Also you are loading the block, but your screenshot is of the page display, so it is not at all relevant to the question. – Neograph734 Oct 8 '17 at 15:42

Try to use $term->term_id instead of $term->name in views_embed_view()

You can get it programmatically by loading taxonomy term through taxonomy_term_load() function and passing it to views_embed_view() as a third argument

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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