• Resolved fedorov

    (@fedorov)


    Hello, friends.
    Tell me what to insert into the code:

     <?php
        if (function_exists('wpp_get_views')) 
            echo wpp_get_views( get_the_ID() ); // This will only work when used inside the loop!
    ?>

    so that the view count is updated every 1 minute, not in real time (as in the WPP Cache Expiry Policy settings)
    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there!

    The wpp_get_views() template tag doesn’t have such a feature, so if you don’t want it to show the “live” views count but a “cached” version of it you can use transients (which is what the “WPP Cache Expiry Policy settings” is actually doing behind the scenes):

    <?php
    
    if ( function_exists( 'wpp_get_views' ) ) {
    
        if ( false === ( $views_count = get_transient( 'wpp_views_count_' . get_the_ID() ) ) ) {
    
            // Get views count.
            $views_count = wpp_get_views( get_the_ID() );
    
            // Put the results in a transient. Expire after 1 minute.
    	set_transient( 'wpp_views_count_' . get_the_ID(), $views_count, 1 * MINUTE_IN_SECONDS );
    
        }
    
        echo $views_count;
    
    }
    
    ?>
    Thread Starter fedorov

    (@fedorov)

    @hcabrera Thank you so much. Working!

    • This reply was modified 7 years, 6 months ago by fedorov.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Delay in counter updates (cache)’ is closed to new replies.