• Resolved protoo

    (@protoo)


    I used the hook for authors to earn when their posts are viewed.
    Is there code to show content view count of each post in the frontend of each post?

Viewing 3 replies - 1 through 3 (of 3 total)
  • A.Tariq

    (@arsalantariq)

    Hi @protoo,

    Thank you for contacting us, Please use the below-shared code to achieve what you are looking for.

    global $wpdb, $mycred_log_table;
    $total_views = $wpdb->get_var( "SELECT COUNT(*) FROM where ref = 'view_content' && ref_id = YOUR_POST_ID {$mycred_log_table}" );
    Thread Starter protoo

    (@protoo)

    I put the code in single.php but it doesn’t show the view count.

    Does the “Viewing content” for post authors work by ip?
    Like, does it count each view on a post with each ip address to prevent spam view?

    A.Tariq

    (@arsalantariq)

    Hi @protoo,

    Please use the below-shared code.

    global $wpdb, $mycred_log_table;
    $total_views = $wpdb->get_var( "SELECT COUNT(*) FROM {$mycred_log_table} where ref = 'view_content' AND ref_id = YOUR_POST_ID" );

    replace YOUR_POST_ID with your post id.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Show content view count in frontend’ is closed to new replies.