admin管理员组文章数量:1279175
I’m trying to sort products by attribute value.
The attribute value is alphanumeric
I started from this code
Trying with the following code
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args');
function custom_woocommerce_get_catalog_ordering_args( $args ) {
global $wp_query;
// Changed the $_SESSION to $_GET
if (isset($_GET['orderby'])) {
switch ($_GET['orderby']) :
case 'pa_feat' :
$args['order'] = 'ASC';
$args['meta_key'] = 'pa_feat';
$args['orderby'] = 'meta_value';
break;
endswitch;
}
return $args;
}
The values are ordered as follows:
0,1 g 0,2 g 0,3 g 0,4 g 0,5 g 0,6 g 0,7 g 0,8 g 0,9 g 0,0 g 0,45 g
The value 0,0 g should be the first and 0,45 g should come after 0,4 g and before 0.5 g
i tried to edit
$args['orderby'] = 'meta_value';
with
$args['orderby'] = 'meta_value_num';
$args['meta_type'] = 'NUMERIC'
or
$args['orderby'] = 'meta_value_num';
$args['meta_type'] = 'DECIMAL'
but so the result is a completely wrong order.
I would like the correct ordering of attribute products to be:
0,0 g 0,1 g 0,2 g 0,3 g 0,4 g 0,45 g 0,5 g 0,6 g 0,7 g 0,8 g 0,9 g
Thanks in advance for your suggestions
Frank
本文标签: customizationWPQuerysort the results by meta value custom attribute wocoomerce
版权声明:本文标题:customization - WP_Query - sort the results by meta value custom attribute wocoomerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741287630a2370363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论