2

I have a custom post type (cpt_roundtable), and am trying to add a column to the admin page showing the menu_order for each entry. This is in my functions.php file.

function set_roundtable_columns($columns) {
    return array(
        'cb' => '<input type="checkbox" />',
        'title' => __('Title'),
        'taxonomy-sessions' => __('Session'),
        'menu_order' => __('Order'),
        'date' => __('Date'),
    );
}
add_filter('manage_cpt_roundtable_posts_columns' , 'set_roundtable_columns');

It works perfectly except that the 'Order" column does not populate. I guess I have the incorrect term name for that field(?)

Do I have to write a function to populate this column even though it's not a custom field?

2

Yes, you need to write code to populate it. This is untested but should work.

add_filter('manage_edit-cpt_roundtable_columns', 'init_roundtable_custom_columns');

function init_roundtable_custom_columns($columns)
{
    return array(
        'cb' => '<input type="checkbox" />',
        'title' => __('Title'),
        'taxonomy-sessions' => __('Session'),
        'menu_order' => __('Order'),
        'date' => __('Date'),
    );
}

add_action('manage_cpt_roundtable_posts_custom_column', 'manage_roundtable_custom_columns', 10, 2);

function manage_roundtable_custom_columns($column, $post_id)
{
    $the_post = get_post($id);

    switch ($column)
    {
        case 'menu_order' :

            echo $the_post->menu_order;
            break;
    }
}
|improve this answer|||||
  • Thank you! Works perfectly (after removing the extraneous ")" on the first line! – Diana Nichols Oct 17 '14 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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