【发布时间】:2017-01-31 18:19:29
【问题描述】:
我正在尝试更改 woocommerce 管理屏幕中的默认排序顺序。
我正在尝试使用以下代码默认按产品名称对产品页面进行排序。
/* Sort posts in wp_list_table by column in ascending or descending order. */
function custom_post_order($query){
/*
Set post types.
_builtin => true returns WordPress default post types.
_builtin => false returns custom registered post types.
*/
$post_types = get_post_types(array('_builtin' => false), 'names');
/* The current post type. */
$post_type = $query->get('post_type');
/* Check post types. */
if(in_array($post_type, $post_types) && $post_type == 'product'){
/* Post Column: e.g. title */
if($query->get('orderby') == ''){
$query->set('orderby', 'title');
}
/* Post Order: ASC / DESC */
if($query->get('order') == ''){
$query->set('order', 'ASC');
}
}
}
if(is_admin()){
add_action('pre_get_posts', 'custom_post_order');
}
但它似乎不起作用。谁能指出我哪里出错了或者woocommerce处理产品列的方式不同。
【问题讨论】:
标签: wordpress woocommerce