Search code examples
phpwordpresspluginshookcustom-post-type

How add custom fileld to custom article listing page


I have created a custom post type. I am trying to display each post click and views counts in custom articles listing page (see screenshot), but no success.

enter image description here


Solution

  • You can add it like this. You will need to adjust for your post types and field names. In this example I will use the post type of 'custom-articale' and field name of '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');
        }
    }