• Hello,

    The greatest plugin from all others i used. But i use a litle code for showing the page views (counter) wich not working right with the wp super cache.
    i.e.After 3 hour that a post is published the views counter shows still 0 or 5, and this is not normal. I have more views and i lost the counts.

    In the plugin settings i use MOD_REWRITE.

    The php code is:

    <?php
    function getPostViews($postID){
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
            return "0";
        }
        return ' '. $count;
    }
    function setPostViews($postID) {
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            $count = 0;
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
        }else{
            $count++;
            update_post_meta($postID, $count_key, $count);
        }
    }
    
    // Remove issues with prefetching adding extra views
    remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
    ?>

    <?php echo getPostViews(get_the_ID()); ?>
    <?php setPostViews(get_the_ID()); ?>

    Is there any solution to work properly this system?

    Thank you.

    https://www.ads-software.com/plugins/wp-super-cache/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Apparently it works like this:
    https://z9.io/2013/10/21/shiny-new-dynamic-content-wp-super-cache/

    I haven’t gotten it to work myself so if you manage to do so it would be great if you could post a small tutorial or something.

    Thread Starter David

    (@buy4me)

    unfortunately i have no idea how to figure this.
    is something like:
    <?php .... { ?>MY CODE<?php } ?>

    Can someone post an example?

    Thread Starter David

    (@buy4me)

    ok. unistalled if no one helps.

    Thank you

    I’m trying to do the exact same thing. Unfortunately, all the tutorials and threads don’t seem to explain where the different pieces of code need to be placed.

    I have a single post-views.php file that I need to exclude from caching, and i’d be grateful if someone could simplify in simple language what z9.io and the dynamic-cache-test.php are explaining on what to do.

    Okay, I’ve found a workaround to my problem.

    Primarily I needed the post views counter to work even when cached pages are viewed, so I found this plugin Ajaxize which converted my post-views function to ajaxed div. I added this new div to my footer.php, so it keeps tracks of my views dynamically.

    Even though the counter doesn’t update until a new cache file is generated, the total post views tracking works fine.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to not cache a php code function?’ is closed to new replies.