How can I add columns to the post edit listing to show my custom post data?

You add the column using the manage_posts_column filter, where you add two new array elements with a custom key name and the header name as the value.

add_filter('manage_posts_columns', 'wpse_3531_add_seo_columns', 10, 2);
function wpse_3531_add_seo_columns($posts_columns, $post_type)
{
    $posts_columns['seo_score'] = 'SEO score';
    $posts_columns['seo_keyword'] = 'SEO keyword';
    return $posts_columns;
}

The function that displays each row, _post_row(), then fires the manage_posts_custom_column action for each column that it does not know. You hook into this function to display your own data.

add_action('manage_posts_custom_column', 'wpse_3531_display_seo_columns', 10, 2);
function wpse_3531_display_seo_columns($column_name, $post_id)
{
    if ('seo_score' == $column_name) {
        echo 'SEO score for post with ID ' . $post_id;
    }
    if ('seo_keyword' == $column_name) {
        echo 'SEO keyword for post with ID ' . $post_id;
    }
}

Leave a Comment