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?

1 Answer
1

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;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *