Sort CPT archive by order prevents sorting in admin
I've activated the Order feature for my 'portfolio' CPT and have managed to arrange my 'portfolio' posts according to respective Order values I've provided.
Unfortunately, I've found that this code locks the order that 'portfolio' items are displayed in admin; I can't toggle the Title ascending/descending feature nor am I able to sort this list by Date.
My goal is to display these 'portfolio' items on the live site using the Order feature but I'd still like to be able to make use of the Title/Date sorting in admin.
//add order column to admin listing screen
function add_new_portfolio_column($post_columns) {
$post_columns['menu_order'] = Order;
return $post_columns;
}
add_action('manage_edit-portfolio_columns', 'add_new_portfolio_column');
//show custom order column values
function show_order_column($name){
global $post;
switch ($name) {
case 'menu_order':
$order = $post-menu_order;
echo $order;
break;
default:
break;
}
}
add_action('manage_portfolio_posts_custom_column','show_order_column');
//make column sortable
function order_column_register_sortable($columns){
$columns['menu_order'] = 'menu_order';
return $columns;
}
add_filter('manage_edit-portfolio_sortable_columns','order_column_register_sortable');
//Sort post archive by menu_order
add_action( 'pre_get_posts', 'mpe_portfolio_sort_order');
function mpe_portfolio_sort_order($query){
if(is_archive() ):
$query-set( 'order', 'ASC' );
$query-set( 'orderby', 'menu_order' );
endif;
};
Topic menu-order screen-columns order page-attributes custom-post-types Wordpress
Category Web