Views Shortcode filter by taxonomy

Support MB Views Views Shortcode filter by taxonomyResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #33396
    ChrisChris
    Participant
    1. I setup a custom post type reviews
    2. I added a taxonomy review-tags

    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

    #33399
    Long NguyenLong Nguyen
    Moderator

    Hi Chris,

    Please refer to this topic to query posts with taxonomy arguments
    https://support.metabox.io/topic/create-filter-by-category/

    #33405
    ChrisChris
    Participant

    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"]

    #33422
    Long NguyenLong Nguyen
    Moderator

    Hi Chris,

    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

    #33437
    ChrisChris
    Participant

    Can you give me code example on how to use this?

    #33441
    Long NguyenLong Nguyen
    Moderator

    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"]

    #33443
    ChrisChris
    Participant

    Thank you very much!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.