Attribute numeric range filter
-
Hi,
I am trying to filter a Woocommerce attribute by numeric range.
Woocommerce attributes are text based, but there are some plugins around that offer attribute filter by range.
Any idea how to setup a non-numeric range?<?php if ( woocommerce_product_loop() ) { $prodLenghtMin = intval( $prodLenghtMin ); $prodLenghtMax = intval( $prodLenghtMax ); $range = range($prodLenghtMin, $prodLenghtMax); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'orderby'=>'title', 'order' => 'ASC', 'paged' => $paged ); if ( $prodColor || $prodBrand || $prodLenghtMin || $prodLenghtMax ) { $args['tax_query'] = array(); if ( $prodColor ) { $args['tax_query'][] = array( 'taxonomy' => 'pa_color', 'field' => 'slug', 'terms' => $prodColor ); } if ( $prodBrand ) { $args['tax_query'][] = array( 'taxonomy' => 'pa_width', 'field' => 'slug', 'terms' => $prodBrand ); } // this doesn't work: if ( $prodLenghtMin || $prodlenghtMax ) { $args['tax_query'][] = array( 'taxonomy' => 'pa_lenght', 'field' => 'slug', 'type' => 'NUMERIC', 'terms' => $range ); } // end this doesn't work } $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); global $product; // [...] endwhile; wp_reset_postdata(); }?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Attribute numeric range filter’ is closed to new replies.