Title: Initial view count
Last modified: August 21, 2016

---

# Initial view count

 *  [Anders](https://wordpress.org/support/users/anme/)
 * (@anme)
 * [13 years ago](https://wordpress.org/support/topic/initial-view-count/)
 * I made the following modification to bbp-topics.view.php to get an initial view
   count without having to view each post first.
 *     ```
       function btv_get_topic_view_count( $topic_id = 0 ) {
         $topic_id = bbp_get_topic_id( $topic_id );
   
         if ( empty( $topic_id ) )
           return 0;
   
         $views = (int) get_post_meta( $topic_id, '_btv_view_count', true );
   
         /**** begin modification ****/
         if ( $views == 0 ) {
           $views = bbp_get_topic_post_count( $topic_id );
   
           if ( $views > 1 )
             $views = $views + bbp_get_topic_reply_count_hidden( $topic_id );
   
           update_post_meta( $topic_id, '_btv_view_count', $views );
         }
         /**** end modification ****/
   
         return $views;
       }
       ```
   
 * [http://wordpress.org/extend/plugins/bbp-topic-views/](http://wordpress.org/extend/plugins/bbp-topic-views/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Robin W](https://wordpress.org/support/users/robin-w/)
 * (@robin-w)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/initial-view-count/#post-3804520)
 * Thanks anders, that has made a big difference to my forums, they are quite old
   and lots of zeros looked funny.
 * Great tweak !
 * Since you’ve obviously poked this code, I can see it on the topics page,but would
   be great to add it to an individual topic display.
 * eg where it says
    “This topic contains 2 replies, has 2 voices, and was last 
   updated by Matthew 1 week, 1 day ago.” Would be good to add …”and has been viewed
   15 times.”
 * Before I spend hours seeing if this is easy, can you supply a quick fix?
 *  Thread Starter [Anders](https://wordpress.org/support/users/anme/)
 * (@anme)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/initial-view-count/#post-3804521)
 * I’m afraid I can’t help you with that.
 * I’ve disabled the “This topic contains blah blah…” on my own site. It’s inserted
   by the call to `bbp_single_topic_description()` in content-single-topic.php.
 *  [Robin W](https://wordpress.org/support/users/robin-w/)
 * (@robin-w)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/initial-view-count/#post-3804522)
 * “I’m afraid I can’t help you with that.” – quite the opposite ! – this was exactly
   the time saving I needed to find and sort this and have sorted most of my problem
   out.
 * But I need one more small bit of help if I may?
 * I created a new function/action that is called by content-single-topic.php using
   the bbp_template_before_single_topic action hook, and I have this all in a revised
   btv plugin, including your great code.
    This creates a revised version that has
   just what I want, and adds it as a new line.
 * But I now need to get rid of the original bbp_single_topic_description() as this
   repeats the old line, so I have the right text, followed by the wrong text.
 * You say you disabled the “this topic”…etc. How did you do this? Obviously I can
   simply comment out the code line in content-single-topic, but is there a smarter
   way to do this so that code is not over-written by later versions?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Initial view count’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/bbp-topic-views.svg)
 * [bbP Topic Views](https://wordpress.org/plugins/bbp-topic-views/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/bbp-topic-views/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/bbp-topic-views/)
 * [Active Topics](https://wordpress.org/support/plugin/bbp-topic-views/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bbp-topic-views/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bbp-topic-views/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Robin W](https://wordpress.org/support/users/robin-w/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/initial-view-count/#post-3804522)
 * Status: not resolved