Lost visits counter when updating theme

Posted in: Newsmag
Post count: 16

Good evening,

I just realized that after changing the templete, the post visits counter is back to zero.

Please, help me to re-set the counter as it was before doing this change…

Thanks in advance

Post count: 9544

The theme uses a different custom field for the counter; so you need to edit the /includes/wp-booster/td_page_views.php
file or similar.

a) figure out what the name of the custom field was for your old hit counter (e.g., on my sites it was ‘views’)

b) then edit this line at top of the page views file to match your custom field; e.g.,
static $post_view_counter_key = 'views';

Post count: 16

Thanks for your quick answer Chris S.

Below I share what I found from the “functions.php” of Papillon templete. I do not know which is the one I should change in the:
STATIC $POST_VIEW_COUNTER_KEY = ‘VIEWS’;

If I change this, and someone visit the post, will it continue counting adding visits to the post?

Below whay I found related with post views:
a)
$post_views = getViews(get_the_ID());

b)
<i class=”fa-clock-o”></i> <span>’ . $post_time . ‘</span> <i class=”fa-eye”></i> <span>’. $post_views.'</span> <i class=”fa-comment-o”></i> <span>’ . $post_comments . ‘</span>

c)
function setViews($postID) {
$count_key = ‘webnus_views’;
$count = get_post_meta($postID, $count_key, true);
if($count==”){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, ‘0’);
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
return $count; /* so you can show it */
}
function getViews($postID) {
$count_key = ‘webnus_views’;
$count = get_post_meta($postID, $count_key, true);
if($count==”){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, ‘0’);
}
return $count; /* so you can show it */
}

Thanks in advance for your help! I am not familiar with web coding… I create it with visual composer because I do not know how to code.

Post count: 9544

the view count field should be a custom field as part of all your posts, look at the custom fields at bottom of the posts to see what the hit counter field actually is, like ‘views’ or “Views” or “hits” or “Count” or whatever.

you might try ‘webnus_views‘ and see if the count then shows on your posts.

Be sure to make back up of your dbase FIRST, which you should already have done before changing themes!

Post count: 16

Dear Chris,

I tried to substitute “post_views_count” in the sentence of the code you indicated me in your first reply by ‘websnus_views’ but didn’t work. I also tried to do it with ‘views’, ‘Views’, ‘hits’ and some other and didn’t work either.

I took the last post published with the Papillon templete and checked the code: view-source:http://www.glutenfreeadventures.net/es/restaurantes-sin-gluten-en-tel-aviv-israel-segunda-parte/

I looked for the sentence STATIC $POST_VIEW_COUNTER_KEY and it does not appear anywhere.

I do not know exactly what word should I look for in the page code in order to identify what is the wording to be changed to recover the views counter that I had with the old templete… could you help me on that please?

Another question I have is that if after recovering the old count (for example, having 900 visits in the last post) someone visits this post again, will this continue counting from this point on, showing 901?

Thanks in advance for your help,

Post count: 9544

Look for custom field bottom of a post, the name of custom field is there… not in code of public page, but in post editor

  • This reply was modified 8 years by simchris.
Post count: 16

Dear Chris,

I kindly ask you to give me more indications of what should I look for in the post editor and how to do it. This is my first website and I am not familiar with the technical details you ask me to look for.

Thanks in advance

Post count: 9544

Hi
i don’t work here …

see if you can turn on visibility to for custom fields on your posts.. there should be a custom field for your former ‘views’ … if not, you’d have to look in your dbase to find the right field name; or just start from scratch with the new counter, which you’ll see on the posts custom fields from the theme

https://codex.wordpress.org/Administration_Panels#Screen_Options

I am surprised the field isn’t called webnus_views based on the code you specified.

I can’t really be much more help here.

Post count: 16

Hi Chris S,

You were right with the custom field “webnus_views” but I didn’t succeed on editing the php file you indicated in the first answer.

In any case, your last answer was the key to solve the problem!

thanks a lot for your patience and good help! Really appreciate it!

Post count: 9544

No worries. 🙂

I had to do this way back when, as all our old sites had ‘views’ or ‘Views’ — and then our plugin was adding double hits before I realized I had to disable plugin vs trying to hack that out of the theme.

… so, just remember you need to edit that file every time you update the theme!

TIP: keep that in your list of backup stuff in a folder someplace for your overall site project. Glad you got it sorted.

I did suggest they add that as a theme panel option at some point, but considering it’s now 4 years later, I don’t think I will hold my breath on that 😉

Viewing 10 posts - 1 through 10 (of 10 total)
The forum ‘Newsmag’ is closed to new topics and replies.