Join the Soledad Facebook Users Group here
for Share, assistance, discussion, and Updates related to Soledad WordPress Theme.

If you can't create a new ticket - you can send us an email via our contact form and we will get back to you.

Okay
  Public Ticket #2854549
Post Views in Backend
Closed

Comments

  •  1
    DerekAMG started the conversation

    Hi there, 
    I'm trying to find a way to show the total post views in the backend of the site for each story. I don't want them on the articles as it sets them all to 0 when I do that and some are locked into the paywall so have fewer views. I want to be able to see the post views for each story in the backend in a column on the posts page. Or at least in the post views panel we see if we un-tick: Hide Post Views.
    I'm sure I'm not the only one who would find this very helpful.

    Thanks Derek

  •  2,576
    PenciDesign replied

    Hi,

    Please install the Code Snippet plugin, then create a new snippet with the following content:

    add_filter( 'manage_edit-post_columns', 'derekamg_view_columns' );
    function derekamg_view_columns( $columns ) {
        $columns['views'] = 'Views';
        return $columns;
    } add_action( 'manage_posts_custom_column', 'derekamg_show_view_columns' );
    function derekamg_show_view_columns( $name ) {
        global $post;
        switch ( $name ) {
            case 'views':
                $all_times_views = get_post_meta( $post->ID, 'penci_post_views_count', true );
                $week_views = get_post_meta( $post->ID, 'penci_post_week_views_count', true );
                $month_views = get_post_meta( $post->ID, 'penci_post_month_views_count', true );             $month_views = $month_views ? $month_views : 0;
                $week_views = $week_views ? $week_views : 0;
                $all_times_views = $all_times_views ? $all_times_views : 0;             echo 'All time views: <strong>' . $all_times_views . '</strong><br/>';
                echo 'Week views: <strong>' . $week_views . '</strong><br/>';
                echo 'Month time views: <strong>' . $month_views . '</strong>';
                break;
        }
    }

    Regards,
    PenciDesign.


  •  1
    DerekAMG replied

    Can I just check that code is correct? It's definitely showing the column with all views, weekly and monthly in the posts page (excellent) but all seem to be stuck on 0. Even though we've had views. Not sure the counter is drawing correctly. 

    Derek

  •  2,576
    PenciDesign replied

    Hi,

    If the previous doesn't show post view, please try to replace it with this code:

    add_filter( 'manage_edit-post_columns', 'derekamg_view_columns' );
    function derekamg_view_columns( $columns ) {
        $columns['views'] = 'Views';
        return $columns;
    }
    add_action( 'manage_posts_custom_column', 'derekamg_show_view_columns' );
    function derekamg_show_view_columns( $name ) {
        global $post;
        switch ( $name ) {
            case 'views':
                $all_times_views = get_post_meta( $post->ID, '_count-views_all', true );
                $week_views = get_post_meta( $post->ID, '_count-views_week', true );
                $month_views = get_post_meta( $post->ID, '_count-views_month', true );
                $month_views = $month_views ? $month_views : 0;
                $week_views = $week_views ? $week_views : 0;
                $all_times_views = $all_times_views ? $all_times_views : 0;
                echo 'All time views: <strong>' . $all_times_views . '</strong><br/>';
                echo 'Week views: <strong>' . $week_views . '</strong><br/>';
                echo 'Month time views: <strong>' . $month_views . '</strong>';
                break;
        }
    }

    Regards,
    PenciDesign.


  •  1
    DerekAMG replied

    That still doesn't seem to be showing views – just 0s across the board even when I have clicked through certain posts. Strange. 

  •  2,576
    PenciDesign replied

    Hi,

    Please send me your site login credential in a PRIVATE reply. I'll need to log in & check your config.

    Regards,
    PenciDesign.


  •   DerekAMG replied privately
  •  2,576
    PenciDesign replied

    Hi,

    The post view function doesn't work because you've disabled it on the Customize options.

    I've enabled it by going to Appearance → Customize → General: Enable ajax Post View Count.

    If you don't want to show the post view on the front-end, please go to Appearance → Customize → Additional CSS, add the following custom CSS code:

    .entry-meta-item.penci-post-countview.penci_post-meta_item {
        display: none;
    }

    Regards,
    PenciDesign.


  •  1
    DerekAMG replied

    Thank you, yes that works great now. Really appreciate your help. I don't want the view showing always because we lockdown some stories to encourage more subscribers, but then their view stats are lower.


    Thank you. Great support!

  •  1
    DerekAMG replied

    Really happy with the way this is working but wondered if there was a simple way to restrict the post views data to administrators only? Currently my contributors can see it also. Ideally I'd like them not to be able to.

  •  2,576
    PenciDesign replied

    Hi,

    Please modify the PHP code like this:

    if ( is_admin() && current_user_can( 'manage_options' ) ) {
        add_filter( 'manage_edit-post_columns', 'derekamg_view_columns' );
        add_action( 'manage_posts_custom_column', 'derekamg_show_view_columns' );
    } function derekamg_view_columns( $columns ) {
        $columns['views'] = 'Views';
        return $columns;
    } function derekamg_show_view_columns( $name ) {
        global $post;
        switch ( $name ) {
            case 'views':
                $all_times_views = get_post_meta( $post->ID, '_count-views_all', true );
                $week_views = get_post_meta( $post->ID, '_count-views_week', true );
                $month_views = get_post_meta( $post->ID, '_count-views_month', true );
                $month_views = $month_views ? $month_views : 0;
                $week_views = $week_views ? $week_views : 0;
                $all_times_views = $all_times_views ? $all_times_views : 0;
                echo 'All time views: <strong>' . $all_times_views . '</strong><br/>';
                echo 'Week views: <strong>' . $week_views . '</strong><br/>';
                echo 'Month time views: <strong>' . $month_views . '</strong>';
                break;
        }
    }

    Regards,
    PenciDesign.


  •  1
    DerekAMG replied

    Thank you, that is superb. First class support as always.

    One more question I have is why do my social icons show up as corrupted in my author bios. Facebook, Instagram and LinkedIn are all showing up as a jumble of four letters instead.


  •  2,576
    PenciDesign replied

    Hi,

    Please go to Appearance → Customize → Additional CSS then add the following custom CSS code:

    .author-socials .fa {
        font-family: "FontAwesome";
    }
    Clear your site & browser cache then check again.

    Regards,
    PenciDesign.

  •  1
    DerekAMG replied

    Boom! That's fixed it, thank you so much yet again. 

    Derek