By default pages are order by menu_order
then title
.
When you are adding filter country
you are ordering them by meta_value
There are two options
- Remove everything that you added
country
andorderby
pages will be back to default order. - If you can not remove
orderby
but can removecountry
then adjust your code in this way and order pages again bymenu_order title
only when country is not set andorderby
istype
.
Updated code:-
function type_column_orderby($vars) {
// You can also wrap this code in one more condition using $vars to only alter page list!
if (!empty($_GET['country']) && isset($vars['orderby']) && 'type' == $vars['orderby']) {
$vars = array_merge( $vars, array(
'meta_key' => 'type',
'orderby' => 'meta_value'
));
} else if (empty($_GET['country']) && isset($vars['orderby']) && 'type' == $vars['orderby']) {
$vars = array_merge( $vars, array(
'orderby' => 'menu_order title',
'posts_per_page' => -1
));
}
return $vars;
}
NOTE:
request
filter effect every query so wrap your filter in
load-edit.php
action to only alter the post type listing query.
add_action( 'load-edit.php', 'custom_page_order' );
function custom_page_order() {
add_filter('request', 'type_column_orderby');
}