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
279 stars 83 forks source link

It does not register post views #207

Closed mjgchase closed 5 years ago

mjgchase commented 5 years ago

The plugin seems to not register post views that are requested through the REST API

cabrerahector commented 5 years ago

Hi there,

Hard to say what's going on with just "it doesn't work." You'll need to provide some more details if you want to get help.

For the time being, please try checking these two FAQs:

If none of those help, then please:

  1. Share your site's URL.
  2. Provide a list of currently active plugins.
mjgchase commented 5 years ago

Hi Cabrerahector

When making calls to the rest api endpoint detailed here https://developer.wordpress.org/rest-api/reference/posts/, you can make calls by ID to get a specific post or by slugs , this does not seem to register through your plugin

Hope that clarifies it for you.

cabrerahector commented 5 years ago

Thanks for clarifying.

Indeed, as you already noticed the plugin doesn't update the views count of a post when pulling its data via REST API. This use case wasn't contemplated when REST API support was first added into the plugin and right now you're the first person to ask about it. I had no idea people would want this to be honest.

There's however an endpoint the plugin uses to update the views count that's publicly available: /wp-json/wordpress-popular-posts/v1/popular-posts/. Sending a POST request to that route with the right parameters (I'm not near a computer right now, please check the source code of the WPP's REST API controller for more details) will do the job. There might be a more elegant solution but, again, I'm not near a computer right now to play around with the REST API.

mjgchase commented 5 years ago

Posting to that and point with wpp_id equal to the word press post id works , thanks much appreciated