A Long Time Ago (When I Had Just Set Up My Site), I Started Using the WP Postviews Plugin, Because I Had Enabled a CDN Back Then and Couldn't Count Visits. So I Wrote This Article: “Enabling a CDN in WordPress Does Not Increase View Counts”.

Now I Have Enabled HTML Caching Again. Although the Backend Can Count Visits, the Frontend Pages Still Do Not Refresh. I Had No Choice but to Search for Tutorials Everywhere. Later, I Found the Perfect Solution at Yuezhai-chan, and Now I’m Sharing It with Everyone.

Solution

Step 1: Enter the Plugin Directory /wp-content/plugins/wp-postviews,

Open the postviews-cache.js File, Delete All of Its Existing Code, Add the Following Code, and Press Ctrl+S to Save.

jQuery.ajax({
    type: "GET",
    url: viewsCacheL10n.admin_ajax_url,
    data: "postviews_id=" + viewsCacheL10n.post_id + "&action=postviews",
    cache: !1
});
jQuery(document).ready(function() {
    var ajax_data = {
        action: "show_postview",
        bigfa_view: viewsCacheL10n.post_id
    };
    $.post(viewsCacheL10n.admin_ajax_url, ajax_data,
    function(data) {
        $('.show-view').html(data);
    });
    return false;
});

Step 2: Open the wp-postviews.php File and Add the Following Code at the End

add_action('wp_ajax_nopriv_show_postview', 'show_postview');
add_action('wp_ajax_show_postview', 'show_postview');
function show_postview(){
    $views_options = get_option('views_options');
    $ID = $_POST["bigfa_view"];
    $custom_fields = get_post_custom($ID);
    $my_custom_field = $custom_fields['views'];
    foreach ( $my_custom_field as $key => $value ) {
        echo str_replace('%VIEW_COUNT%', number_format_i18n($value), $views_options['template']);
    }
    die;
}

Good-looking people have already solved the problem perfectly, while ugly people are still struggling desperately. Wahahaha!