I am now experiencing a wired problem with my wordpress installation. I was surprised when I saw post view counter of another post also increased including the the post on which I clicked to try and check the result. I also observed that it increments the post view of another post from the same user.

For more information: I am calling a function from single.php while passing post id to it to display post counter at the bottom of post. In order to trace the issue I used netbeans IDE and found that single.php runs more than once and it passes different post id at first run and subsequently it passes correct post id at the end.

In order to get post id on single.php I used:

<?php $newpostid = get_the_ID(); ?> Total Views <?php echo_views($newpostid); ? echo_views() is a function which directly used to output the updated number using echo statement within it.

Hope someone can help me out of this issue. Thanks.

| improve this question | | | | |
  • It's be the loop in single.php that runs more then once. But… it's a loop - you can expect it to run multiple times. Why don't you call your page-view-update function outside the loop instead, and use a different function for displaying it? – shea Feb 10 '13 at 9:47
  • Where does echo_views() comes from? Please clarify your post and retag it to match the topic. – Max Yudin Feb 10 '13 at 12:15
  • Would this be related to FireFox's Prefetching? – s_ha_dum Feb 10 '13 at 17:09
  • Yes s_ha_dum, the issue is with FireFox's Prefetching technology and many many thanks to lead me to the right direction. – Miraj Feb 11 '13 at 6:25

I am answering this because nobody yet answered this and I think this could help others who are experiencing this kind of issue.

As mentioned by s_ha_dum that the issue is related to FireFox's Prefetching mechanism. In order to resolve this I inserted the below line to function.php:

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.