• Resolved vicetias

    (@vicetias)


    Hello! Just want to know if is there a function to exclude my IP in order to doesn’t count my own views, because a lot of times I need to see my website logged-out.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Héctor Cabrera

    (@hcabrera)

    Hey there!

    Try adding this to your theme’s functions.php file:

    function wpp_ip_exclusion( $post_ID, $views ){
    
        $ip_address = $_SERVER['REMOTE_ADDR'];
        $excluded_ip_addresses = array( 'YOUR-IP-ADDRESS-HERE' );
    
        // Visitor has already seen this page
        if ( in_array( $ip_address, $excluded_ip_addresses ) ) {
            exit();
        }
    
    }
    add_action( 'wpp_pre_update_views', 'wpp_ip_exclusion', 10, 2 );

    Change YOUR-IP-ADDRESS-HERE with your actual IP address.

    Thread Starter vicetias

    (@vicetias)

    Worked, thank you.

    Another question, ‘trending now’ in dashboard shows most viewed posts of the last 24 hours, right? And ‘most viewed’?

    • This reply was modified 4 years, 10 months ago by vicetias.
    • This reply was modified 4 years, 10 months ago by vicetias.
    Plugin Author Héctor Cabrera

    (@hcabrera)

    Take a look at WPP v4 release notes, should clear things out.

    Thread Starter vicetias

    (@vicetias)

    I got it, thanks.

    Thread Starter vicetias

    (@vicetias)

    Please @hcabrera, reply to my question at “How To: Sort a custom query by views”

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘IP’ is closed to new replies.