如何将自定义字段添加到自定义文章列表页面

How add custom fileld to custom article listing page

我创建了一个自定义 post 类型。我正在尝试显示每个 post 自定义文章列表页面中的点击和查看计数(见屏幕截图),但没有成功。

你可以这样添加。您需要调整 post 类型和字段名称。在此示例中,我将使用 post 类型 'custom-articale' 和字段名称 'view-count'.

add_filter('manage_custom-articale_posts_columns', 'reveal_view_count', 1);
add_action('manage_custom-articale_posts_custom_column', 'reveal_view_count_value', 1, 2);

function reveal_view_count($columns)
{
    $columns['view-count'] = 'View Count';
    return $columns;
}

function reveal_view_count_value($column)
{
    if ('view-count' == $column) {
        echo the_field('view-count');
    }
}