Trying to sort alphabetically by custom attribute
-
hi!
I’m trying to sort alphabetically by Artist (pa-esittaja) name and I’m using the code below.
I’ve created a custom attribute (pa-esittaja) but somehow the alphabetical order isn’t quite right. Is there anything I could fix in the code?
add_filter('woocommerce_get_catalog_ordering_args', 'wh_catalog_ordering_args'); function wh_catalog_ordering_args($args) { global $wp_query; if (isset($_GET['orderby'])) { switch ($_GET['orderby']) { //for attribute/taxonomy=pa_esittaja case 'pa-esittaja' : $args['order'] = 'ASC'; $args['meta_key'] = 'pa_esittaja'; $args['orderby'] = 'attribute'; break; case 'pa-esittaja-desc' : $args['order'] = 'DESC'; $args['meta_key'] = 'pa_esittaja'; $args['orderby'] = 'attribute'; break; } } return $args; } add_filter( 'woocommerce_default_catalog_orderby_options', 'wh_catalog_orderby' ); add_filter('woocommerce_catalog_orderby', 'wh_catalog_orderby'); function wh_catalog_orderby($sortby) { $sortby['pa-esittaja'] = 'ARTIST A - Z'; $sortby['pa-esittaja-desc'] = 'ARTIST Z - A'; return $sortby; }
The page I need help with: [log in to see the link]
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘Trying to sort alphabetically by custom attribute’ is closed to new replies.