I’ve been using this function to Display Popular Posts by Views in WordPress http://www.wpbeginner.com/wp-tutorials/how-to-track-popular-posts-by-views-in-wordpress-without-a-plugin/
Then i added w3 total cache and the counter doesn’t get updated as often.
I’ve attempted fragment caching as per the tut and other sources
<!-- mfunc wpb_set_post_views($post_id); --><!-- /mfunc -->
But it isn’t updating the counter. The tut (or any of the others) doesn’t specify whether that line goes in php tags or in the html.
I’ve tried both. In php tags it breaks the page. Outside php tags in the regular html it doesn’t count and just renders as a comment when you view source.
Anyone else had this problem? how did you resolve?
Ta in advance,
Kes
It would go in PHP tags but you would not use the exact code surrounded by PHP tags (I’m only stating this in case you are doing it this way – I’m unsure from your question).
You would do this
<?php mfunc wpb_set_post_views($post_id);?>