【问题标题】:Sort price in FacetWP在 FacetWP 中排序价格
【发布时间】:2017-08-09 17:16:50
【问题描述】:

在 FacetWP 插件(用于 Wordpress)中,我想在“价格”之后对结果进行排序,因此我添加了一个新的自定义过滤器,在他们的文档中进行了描述。目前,排序结果如下所示:

  1. 4.450 欧元
  2. 399 欧元
  3. 3.990 欧元

我认为,代码无法识别最后一个零值。 这是我的代码:

add_filter( 'facetwp_sort_options', function( $options, $params ) {
    $options['price_desc'] = array(
        'label' => 'Price (Highest)',
        'query_args' => array(
            'orderby' => 'price',
            'meta_key' => 'price',
            'order' => 'DESC',
        )
    );
    return $options;
}, 10, 2 );

已经尝试过“usort”功能和替代的“price_raw_short”值(由 mobile.de 提供),但没有任何效果。

【问题讨论】:

    标签: php wordpress sorting zero facetwp


    【解决方案1】:

    你有 Woocommerce 吗? 然后你需要告诉它这是一个数字。 meta_key 也是_price

    升序和降序排序示例:

    $options['price'] = array(
        'label' => __( 'Price: low to high', 'woocommerce' ),
        'query_args' => array(
            'orderby' => 'meta_value_num',
            'meta_key' => '_price',
            'order' => 'asc',
        )
    );
    
    $options['price-desc'] = array(
        'label' => __( 'Price: high to low', 'woocommerce' ),
        'query_args' => array(
            'orderby' => 'meta_value_num',
            'meta_key' => '_price',
            'order' => 'desc',
        )
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-12
      • 2023-02-10
      • 1970-01-01
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 2021-02-12
      相关资源
      最近更新 更多