Querying Terms From Multiple Taxonomies

Support MB Views Querying Terms From Multiple TaxonomiesResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36934
    Chris PChris P
    Participant

    Hi Long,

    Can't seem to figure out how to get this

    $args = array(
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'productgroup',
                'field' => 'slug',
                'terms' => ['briza']
            ),
            array(
                'taxonomy' => 'placement-type',
                'field' => 'slug',
                'terms' => ['wall']
            )
        )
    );

    incorporated into this

    {% set args = { post_type: 'radiator', posts_per_page: -1, tax_query: [{ taxonomy: 'productgroup, placement-type', field: 'slug', terms: term.slug }]  } %}
    				{% set posts = mb.get_posts( args ) %}
    				{% for post in posts %}

    Could you help me out?

    Thanks!

    #36935
    Chris PChris P
    Participant

    This is what I got so far

    
    {% set termGroup = mb.get_the_terms( post.ID, 'productgroup' ) %}
    {% set termType = mb.get_the_terms( post.ID, 'placement-type' ) %}
    
    {% set args = { post_type: 'radiator', posts_per_page: -1, tax_query: [{ relation: 'AND', taxonomy: 'productgroup, placement-type', field: 'slug', terms: termGroup[0].slug, termType[0].slug }]  } %}
    
    {% set posts = mb.get_posts( args ) %}
    
    {% for post in posts %}
    ...
    {% endfor %}
    
    #36948
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Here is an example View code to query posts by multiple terms

    {% set args = { post_type: "post", posts_per_page: 5, tax_query: { 
    	"relation": "AND", 
    	0: { 
    		taxonomy: "category", 
    		field: "slug", 
    		terms: "aciform" 
    	},
    	1: { 
    		taxonomy: "category", 
    		field: "slug", 
    		terms: "cat-a" 
    	}
    } } %}
    
    {% set posts = mb.get_posts( args ) %}
    {% for post in posts %}
    	{{ post.post_title }}
    {% endfor %}
    #36977
    Chris PChris P
    Participant

    Super thx!

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