Support

Account

Home Forums General Issues Count all Post Views

Solved

Count all Post Views

  • 
    <?php		  
    if(is_singular('post')){			  
    $count = get_field('views');			  
    $count++;			  
    update_field('views', number_format($count,0,",","."));
    }	
    ?>

    Through the above code, the post views can be realized, and the refresh will increase by 1. Now I want to count the views of all post on the whole site. How should I count them?

  • The only way to do this without querying the DB directly would be to do a query to get all posts, loop over all the posts, get the count field and add them up.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.