本文介绍了在FacetWP中排序价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在FacetWP插件(适用于Wordpress)中,我想按价格"对结果进行排序,因此我添加了一个新的自定义过滤器,如其文档中所述.当前,排序结果看起来像这样:
In FacetWP Plugin (for Wordpress) I want to sort my results after 'price', so I added a new custom filter, described in their documentation. Currently, the sort results are looking like this:
- 4.450€
- 399欧元
- 3.990€
我认为,代码无法识别最后一个零值.这是我的代码:
I think, the code doesn't recognizes the last zero value.This is my code:
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提供).
Already tried the "usort" function and the alternate 'price_raw_short' value (delivered by mobile.de) with no effect.
推荐答案
您有Woocommerce吗?然后,您需要告诉它它是一个数字.同样meta_key是_price
Do you have Woocommerce?Then you need to tell it that it is a number. Also the meta_key is _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',
)
);
这篇关于在FacetWP中排序价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!