This article mainly introduces the relevant information to manually solve the problem of WordPress WP-PostViews not counting through Ajax. Friends in need can refer to it
A certain website has Memcached turned on and WP-PostViews installed, but I don’t know why the article view count doesn’t work.
After some exploration, I found that WP-PostViews counts by sending requests through ajax. Once the website sees the problem, it simply sends this request.
After some exploration of WordPress background settings and plug-ins, I still can’t find the reason.
Having no choice but to use the ultimate trump card, I manually added the script for this request and added it to the bottom of the page. The code is as follows:
<?php if (is_singular()) : ?> <!-- ajax post view --> <script type= "text/javascript" > $.ajax({ url: "http://***.com/wp-admin/admin-ajax.php" , data: { "postviews_id" : "<?php the_ID(); ?>" , "action" : "postviews" , "_" : new Date ().getTime() } }); </script> <?php endif ; ?>
The above is I compiled it for everyone, I hope it will be helpful to everyone in the future.
Related articles:
Ajax implements the function of registering and selecting an avatar and uploading it
Set Access-Control-Allow-Origin Implementing cross-domain access
Ajax dynamically adding data to the drop-down list implementation method
The above is the detailed content of Manually solve WordPress WP-PostViews not counting issue via Ajax. For more information, please follow other related articles on the PHP Chinese website!