Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to use the menu order attribute to control ordering for a custom post type that's going to be used for a specific purpose.

It's easy enough to add this to the CPT via supports => array('page-attributes') but how do I expose the menu order value on the admin listing screen for this CPT?

share|improve this question

3 Answers 3

up vote 15 down vote accepted

OK - in the end turned out to be fairly simple - as I'd had some kind of mental block - menu_order is a variable in the $post object (thanks to @brady for reminding me of that).

@scribu's post on creating sortable column values then gives the rest.

So, assuming the custom post type is called header_text, these are the functions and hooks that are needed:

Add a new column for the order

/**
* add order column to admin listing screen for header text
*/
function add_new_header_text_column($header_text_columns) {
  $header_text_columns['menu_order'] = "Order";
  return $header_text_columns;
}
add_action('manage_edit-header_text_columns', 'add_new_header_text_column');

Render the column values

/**
* 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_header_text_posts_custom_column','show_order_column');

Set the column to be sortable

/**
* make column sortable
*/
function order_column_register_sortable($columns){
  $columns['menu_order'] = 'menu_order';
  return $columns;
}
add_filter('manage_edit-header_text_sortable_columns','order_column_register_sortable');
share|improve this answer
    
In WP 3.1, manage_edit-${post_type}_columns has been supplanted by manage_${post_type}_posts_columns: codex –  ptriek May 29 '13 at 7:24
    
Is there really just not way to make this the default ordering? Like Pages? –  Howdy_McGee Sep 3 '13 at 21:13

It's been too long, but just for the record, you can display the 'menu order' option in the admin, just by including 'page-attributes' in the 'supports' option array. For example:

    register_post_type( 'columna',
    array(
        'labels' => array(
            'name' => __( 'Columnas' ),
            'singular_name' => __( 'Columna' ),
        ),
        'supports' => array( 'title', 'thumbnail', 'excerpt', 'page-attributes' ),
        'public' => true,
        'has_archive' => false,
        'menu_position'=>5
    )
);
share|improve this answer
1  
The person posting the question is aware of 'page-attributes' already. It must not show the page order value in the way needed. –  s_ha_dum Nov 23 '12 at 23:26

You have to register your CPT with:

'hierachical' => true
share|improve this answer
    
Doesn't that just allows you to specify a parent for the item in the edit screen - I've tried it, and it makes no difference to the listing screen –  anu Feb 29 '12 at 20:24
    
sorry, didn't realize you want to add custom columns to the list ... maybe this gives you a point to start:shibashake.com/wordpress-theme/add-custom-post-type-columns –  ungestaltbar Feb 29 '12 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.