好的,通过一些变通方法解决了这个问题。
在Woocommerce中添加新的排序功能,如:https://gist.githubusercontent.com/bekarice/0df2b2d54d6ac8076f84/raw/wc-sort-by-postmeta.php 很好地工作,但是删除了关于元数据和键的部分,因为我们没有按自定义字段排序(尽管这也是一个很好的解决方法)将orderby更改为“name”。例如,发布slug而不是post title
更改所有产品以删除slug/permalinks中的冒犯词,以便/a-childs-story成为/childs-story,在Woocommerce设置(产品)中选择新的排序选项作为默认选项这是函数的最终代码。php:
/**
* Cool orderby function from Monkey Puzzle. Adapted from:
* Tutorial: http://www.skyverge.com/blog/sort-woocommerce-products-custom-fields/
**/
function monkey_ordering_args( $sort_args ) {
$orderby_value = isset( $_GET[\'orderby\'] ) ? woocommerce_clean( $_GET[\'orderby\'] ) : apply_filters( \'woocommerce_default_catalog_orderby\', get_option( \'woocommerce_default_catalog_orderby\' ) );
switch( $orderby_value ) {
// Name your sortby key whatever you\'d like; must correspond to the $sortby in the next function
case \'slug\':
$sort_args[\'orderby\'] = \'name\';
// Sort by ASC because we\'re using alphabetic sorting
$sort_args[\'order\'] = \'asc\';
break;
}
return $sort_args;
}
add_filter( \'woocommerce_get_catalog_ordering_args\', \'monkey_ordering_args\' );
// Add these new sorting arguments to the sortby options on the frontend
function monkey_add_new_orderby( $sortby ) {
// Adjust the text as desired
$sortby[\'slug\'] = __( \'Sort by name\', \'woocommerce\' );
return $sortby;
}
add_filter( \'woocommerce_default_catalog_orderby_options\', \'monkey_add_new_orderby\' );
add_filter( \'woocommerce_catalog_orderby\', \'monkey_add_new_orderby\' );