Meta Box
Support › MB Views › List taxonomy of a custom field
Hi, I want to list taxonomy in a list on my homepage using views with a shortcode.
I made this and it returns nothing. Some help is welvome
{% set produit-term = mb.get_terms ('gamme') %} <ul class="sidebar"> {% for term in terms %} <li>{{term.name}}</li> {% endfor %} </ul>
Hi Erik,
Follow the WordPress documentation https://developer.wordpress.org/reference/functions/get_terms/
You have to pass an array of parameters to the function get_terms() and assign a value to the parameter taxonomy. Please refer to this topic to get terms in View https://support.metabox.io/topic/loop-through-taxonomy-parent-and-child-terms/
get_terms()
taxonomy
Hi Long, Thanks for you answer. I achieve this but strange {{term.link}} return the homepage link 🙁
<h1>Gamme de produits</h1> <ul class="sidebar"> {% set args = { taxonomy: 'gamme', hide_empty: false } %} {% set terms = mb.get_terms( args ) %} {% for key, term in terms %} <li><a href="{{ term.link }}">{{ term.name }}</a></li> {% endfor %} </ul>
Hi,
You can use the WordPress function to get the term link https://developer.wordpress.org/reference/functions/get_term_link/
Insert a field from the tab Insert Field only works on its location. Please read more here https://docs.metabox.io/extensions/mb-views/#main-query https://docs.metabox.io/extensions/mb-views/#custom-query