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;

//make column sortable
function order_column_register_sortable($columns){
    $columns['menu_order'] = 'menu_order';
    return $columns;

//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' );
  • I included ‘page-attributes’ to ‘portfolio’ CPT ‘supports’ array.
  • ‘portfolio’ CPT’s ‘hierarchical’ parameter is set to true.
    enter image description here
andy 1 month 0 Answers 18 views 0

Leave an answer