Meta Box
Support › MB Views › Views Shortcode filter by taxonomyResolved
I created a view that I want to display by shortcode, the query I use there is
{% set args = { post_type: "reviews", posts_per_page: 999 } %} {% set posts = mb.get_posts( args ) %} {% for post in posts %}
How can I use a tag filter by setting the tag when I use the shortcode?
Regards,
Chris
Hi Chris,
Please refer to this topic to query posts with taxonomy arguments https://support.metabox.io/topic/create-filter-by-category/
Thanks, I used that to edit the code so the shortcode includes the filter but what If I want to set the category while injectign the shortcode?
Like: [mbv name="reviews" custom-taxonomy="cars"] [mbv name="reviews" custom-taxonomy="motorbikes"]
Please follow this documentation to add the custom data to the View shortcode via the custom attribute https://docs.metabox.io/extensions/mb-views/#custom-data
Can you give me code example on how to use this?
Hi,
Here is an example:
{% set args = { post_type: "post", posts_per_page: 6, tax_query: [ { taxonomy: 'category', field: 'slug', terms: my_term } ] } %} {% set posts = mb.get_posts( args ) %} {% for post in posts %} <p>{{ post.post_title }}</p> {% endfor %}
Shortcode:
[mbv name="shortcode" my_term="uncategorized"]
Thank you very much!