作为我问题的背景:在我的页面列表中,我有一组属于国家的页面,这些页面的子页面被分类为“类型”。我有一个这样的页面结构:
Country 1
-- Resource
-- Resource
-- Organisation
-- Overview
Country 2
-- Overview
-- Overview
-- Overview
-- Organisation
Country 3
.
.
.
我添加了一些额外的过滤器,以仅显示选定国家/地区的子页面,当此过滤器运行时,会显示一个额外的列,以显示页面的“类型”。我还添加了必要的代码以使此列可排序。所以我的代码如下:// Add Type column
add_filter(\'manage_pages_columns\', \'my_columns\');
function my_columns($columns) {
if(!empty($_GET[\'country\']) && empty($_GET[\'type\'])) {
$column_type = array(\'type\' => \'Type\');
$columns = array_slice($columns, 0, 2, true) + $column_type + array_slice($columns, 3, NULL, true);
}
return $columns;
}
// Populate Type column
add_action(\'manage_pages_custom_column\', \'my_show_columns\');
function my_show_columns($name) {
if(!empty($_GET[\'country\']) && empty($_GET[\'type\'])) {
global $post;
switch ($name) {
case \'type\':
$type = get_field(\'type\', $post->ID);
echo $type;
}
}
}
// Make Type column sortable
add_filter(\'manage_edit-page_sortable_columns\', \'my_website_manage_sortable_columns\');
function my_website_manage_sortable_columns($sortable_columns) {
if(!empty($_GET[\'country\']) && empty($_GET[\'type\'])) {
$sortable_columns[\'type\'] = \'type\';
}
return $sortable_columns;
}
// Add sort logic
add_filter(\'request\', \'type_column_orderby\');
function type_column_orderby($vars) {
if (isset($vars[\'orderby\']) && \'type\' == $vars[\'orderby\']) {
$vars = array_merge( $vars, array(
\'meta_key\' => \'type\',
\'orderby\' => \'meta_value\'
));
}
return $vars;
}
因此,我可以对类型ASC或DESC进行精细排序,但如何恢复到页面列表的默认排序,其中显示了页面的缩进层次结构?