Notifications
Clear all

New Feature [Solved] Unique Veiws and Reaccuring veiws

15 Posts
3 Users
1 Likes
2,138 Views
ForumLover
Posts: 17
Topic starter
(@forumlover)
Active Member
Joined: 3 years ago

I see that the view count only counts a visitor one time even if they visit the page or post more times. This is not optimal for understanding page views for me. Is there a snippet of code that I can add or remove or both that will allow counting each time the page is loaded? 

Topic Tags
14 Replies
Robert
Posts: 9912
Admin
(@robert)
Support Team
Joined: 7 years ago

Hi @forumlover,

I'm sorry but there is no an easy way to enable it yet. We'll add this in our to-do and make this option.

Reply
ForumLover
Posts: 17
Topic starter
(@forumlover)
Active Member
Joined: 3 years ago

Well it's important I have it sooner than later or I need to go with a different forum that allowes views for returning page visits. Anyway to pay a small fee and get this change? Where in the code does it have the counting?

Reply
4 Replies
Robert
Admin
(@robert)
Joined: 7 years ago

Support Team
Posts: 9912

@forumlover

Ok, you can remove all filters and logics of unique counting of visitors.

For the 1.7.8 and above versions just put this hook code in your current active WordPress theme functions.php file:

add_filter('wpforo_filter_topic_views', '__return_false' );

 

For the 1.7.7 and lower versions do this change in the core file:

Use Plugin Editor or Website cPanle > File manager. Open this file: wp-content/plugins/wpforo/wpf-includes/functions.php

Find this function:

function wpforo_user_logging(){
$data = WPF()->current_object;
$visitor = WPF()->current_user;
if( wpfval($data, 'template') && $data['template'] == 'post' && wpfval($data, 'topicid') ){
//to-do: don't increase views before all read point.
if( WPF()->tools_legal['cookies'] ){
$viwed_ids = wpforo_getcookie( 'wpf_read_topics', false );
if( empty($viwed_ids) || !wpfval($viwed_ids, $data['topicid']) ){
WPF()->db->query("UPDATE `".WPF()->tables->topics."` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
}
}
elseif( is_user_logged_in() ){
if( wpfval(WPF()->current_usermeta, 'wpf_read_topics') ) {
$viwed_db_ids = wpforo_current_usermeta( 'wpf_read_topics' );
if( empty( $viwed_db_ids ) || !wpfval($viwed_db_ids, $data['topicid']) ){
WPF()->db->query("UPDATE `".WPF()->tables->topics."` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
}
} else{
WPF()->db->query("UPDATE `".WPF()->tables->topics."` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
}
}
}
}


Change it to this:

function wpforo_user_logging(){
$data = WPF()->current_object;
$visitor = WPF()->current_user;
if( wpfval($data, 'template') && $data['template'] == 'post' && wpfval($data, 'topicid') ){
WPF()->db->query("UPDATE `".WPF()->tables->topics."` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
}
}
Reply
ForumLover
(@forumlover)
Joined: 3 years ago

Active Member
Posts: 17

@robert

Let me test this.

Reply
Robert
Admin
(@robert)
Joined: 7 years ago

Support Team
Posts: 9912

@forumlover

Remember, the view count will not be changed live-time. Because it's under caching, it'll be reset after each new post or topic. If you want to test it you should click on [Delete all cache] button in Dashboard > Forums > Dashboard after each visit.

So the counting is going well but it'll not change the value on forum after each visit.

Reply
VereK
(@verek)
Joined: 5 years ago

Honorable Member
Posts: 393

@robert

It's actually damn near live, a simple click back on the breadcrumbs will show the view count update.

Nice one. 👍 

Reply
ForumLover
Posts: 17
Topic starter
(@forumlover)
Active Member
Joined: 3 years ago

I have not tested but this reminds me of back in the day when people helped people without trying to charge them freaking as much as they can.

Reply
ForumLover
Posts: 17
Topic starter
(@forumlover)
Active Member
Joined: 3 years ago

Where is this located?

 

  • wpforo.php
  • wpf-assets folder
  • wpf-themes folder
  • wpf-includes folder
  • wpf-languages folder
  • wpf-admin

 

Reply
Page 1 / 3