cabrerahector / wordpress-popular-posts

WordPress Popular Posts - A highly customizable WordPress widget that displays your most popular posts.
https://wordpress.org/plugins/wordpress-popular-posts/
GNU General Public License v2.0
280 stars 82 forks source link

How do I trigger the post count when using WordPress API #280

Closed f1uk3r closed 3 years ago

f1uk3r commented 3 years ago

I am using WordPress API as a backend to my blog app. I hit www.mywebsitename.com/blog/{someId} to get the content of an article, but it doesn't trigger the count in this plugin. Is there a way I can trigger the count when I hit WP API?

cabrerahector commented 3 years ago

Hi @f1uk3r,

Please have a look here: WPP with an AJAX-based site.

f1uk3r commented 3 years ago

Sorry for late reply @cabrerahector

I don't think the link you send me is very relevant to my question. I apologise I didn't told you that I am using Vue.js for the frontend.

But your link led me to another one of your answers and I tried using blog.example.com/wp-json/wordpress-popular-posts/v1/popular-posts?wpp_id=463 to register the count, but it is still not happening. I am just receiving an empty Array/List. What am I doing wrong here?

cabrerahector commented 3 years ago

Hey @f1uk3r,

I don't think the link you send me is very relevant to my question. I apologise I didn't told you that I am using Vue.js for the frontend.

Vue is just another JavaScript framework. The solution still applies in your case: you need to send a POST request to the mentioned REST API endpoint with the parameters as described on the link I shared above. Use either the XMLHttpRequest object or Axios to do so.

What am I doing wrong here?

I'm not familiar enough with Vue.js to be able to help with actual code, but:

  1. Make sure you're sending a POST request (from your comments above it seems to me that you sent a GET request instead),
  2. Make sure you're passing the required parameters to the endpoint (including passing the post/page ID with the wpp_id parameter),
  3. Make sure no third-party plugins are blocking/restricting access to the endpoint.
f1uk3r commented 3 years ago

Make sure you're sending a POST request (from your comments above it seems to me that you sent a GET request instead)

I don't know how I can be this stupid. I was pretty sure I usedPOST request, but I guess I didn't. Thanks anyways.