Home > Web Front-end > JS Tutorial > body text

Manually solve WordPress WP-PostViews not counting issue via Ajax

亚连
Release: 2018-05-24 11:27:23
Original
1617 people have browsed it

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 ; ?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template