Wordpress WooCommerce分层Nav产品过滤器小部件-多个属性无法按预期工作

Wordpress WooCommerce分层Nav产品过滤器小部件-多个属性无法按预期工作,wordpress,filter,attributes,woocommerce,Wordpress,Filter,Attributes,Woocommerce,我对WooCommerce和使用分层导航小部件一次按多个属性过滤有问题。我知道还有其他几个插件提供ajax过滤,但是他们的文档似乎没有表明他们会解决这个问题,而WC文档也没有提供任何关于这个问题的信息。我不知道我是否遗漏了一些明显的东西,因为我想象每个使用过滤器的网站都希望它们按照我在下面概述的方式工作,而不是像现在这样工作 我的网站使用三个属性: -颜色 -服装类型 -烙印 我在侧边栏中设置了3个分层导航小部件的实例,以允许客户找到他们想要的东西。对于所有3个,我都使用OR的查询类型,因此如果

我对WooCommerce和使用分层导航小部件一次按多个属性过滤有问题。我知道还有其他几个插件提供ajax过滤,但是他们的文档似乎没有表明他们会解决这个问题,而WC文档也没有提供任何关于这个问题的信息。我不知道我是否遗漏了一些明显的东西,因为我想象每个使用过滤器的网站都希望它们按照我在下面概述的方式工作,而不是像现在这样工作

我的网站使用三个属性: -颜色 -服装类型 -烙印

我在侧边栏中设置了3个分层导航小部件的实例,以允许客户找到他们想要的东西。对于所有3个,我都使用OR的查询类型,因此如果客户启用蓝色、绿色和红色过滤器选项,他们可以看到任何蓝色、绿色或红色的产品。品牌和服装类型也是如此

我陷入困境的地方是,这些小部件似乎没有一个选项来指定属性之间的AND或or。当我在网站上使用衣服过滤器时,我会想到以下逻辑:

颜色:绿色或蓝色 和 品牌:耐克或阿迪达斯 和 类型:附件或顶部或底部

但事实上,所有东西都只是一个长长的问号,所以一件衣服可以是蓝色的,也可以是配件,也可以是耐克、格林或阿迪达斯

结果是,客户得到了很多他们不想看到的产品,例如,一个彪马产品出现是因为它是蓝色的,即使品牌过滤器只想要耐克或阿迪达斯

有没有办法将查询链接在一起,以便在一个属性中使用OR,但在多个属性中使用AND?我想这个SQL查询不会太复杂,我只是希望有一个扩展可以为我处理这个问题


提前谢谢

/woocommerce/includes/cass-wc-query.php 729行。 按如下方式更改功能分层导航查询:

/**
 * Layered Nav post filter.
 *
 * @param array $filtered_posts
 * @return array
 */
public function layered_nav_query( $filtered_posts ) {
    global $_chosen_attributes;

    if ( sizeof( $_chosen_attributes ) > 0 ) {

        foreach ( $_chosen_attributes as $attribute => $data ) {
            $matched_products_from_attribute = array();
            $filtered = false;

            if ( sizeof( $data['terms'] ) > 0 ) {
                foreach ( $data['terms'] as $value ) {

                    $args = array(
                        'post_type'     => 'product',
                        'numberposts'   => -1,
                        'post_status'   => 'publish',
                        'fields'        => 'ids',
                        'no_found_rows' => true,
                        'tax_query' => array(
                            array(
                                'taxonomy'  => $attribute,
                                'terms'     => $value,
                                'field'     => 'term_id'
                            )
                        )
                    );

                    $post_ids = apply_filters( 'woocommerce_layered_nav_query_post_ids', get_posts( $args ), $args, $attribute, $value );

                    if ( ! is_wp_error( $post_ids ) ) {

                        if ( sizeof( $matched_products_from_attribute ) > 0 || $filtered ) {
                            $matched_products_from_attribute = $data['query_type'] == 'or' ? array_merge( $post_ids, $matched_products_from_attribute ) : array_intersect( $post_ids, $matched_products_from_attribute );
                        } else {
                            $matched_products_from_attribute = $post_ids;
                        }

                        $filtered = true;
                    }
                }
            }

            $results = isset($results)
                ? array_intersect($results, $matched_products_from_attribute)
                : $matched_products_from_attribute;

            $this->filtered_product_ids_for_taxonomy[ $attribute ] = $matched_products_from_attribute;
        }

        if ( $filtered ) {

            WC()->query->layered_nav_post__in   = $results;
            WC()->query->layered_nav_post__in[] = 0;

            if ( sizeof( $filtered_posts ) == 0 ) {
                $filtered_posts   = $results;
                $filtered_posts[] = 0;
            } else {
                $filtered_posts   = array_intersect( $filtered_posts, $results );
                $filtered_posts[] = 0;
            }

        }
    }
    return (array) $filtered_posts;
}

什么为什么?请多解释一下,特别是因为行看起来不正确,而且该函数从2.6.0开始就被弃用了。。