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

REST API doesn't return featured image urls #252

Closed visualcookie closed 4 years ago

visualcookie commented 4 years ago

Describe the bug When calling wp-json/wordpress-popular-posts/v1/popular-posts, the returned posts don't include featured image urls, instead there's featured_media being returned with the ID of the featured image.

To Reproduce Steps to reproduce the behavior:

  1. Make an API call to wp-json/wordpress-popular-posts/v1/popular-posts

Expected behavior JSON should return featured images in different sizes, ideally without forcing the developer to make another API call for EACH post to get the featured image urls.

Environment:

cabrerahector commented 4 years ago

Hi @visualcookie,

I wouldn't label this as a "bug."

This endpoint returns basically the same response as the core /wp/v2/posts endpoint which doesn't include the featured image URL either, just the featured image ID.

I haven't tried this but apparently this is one of the ways people use to have the posts endpoint include the featured image URL from the REST API: https://wordpress.stackexchange.com/a/317331/135534. I believe it should work with WPP's endpoint too so please give it a try and report back the results.

visualcookie commented 4 years ago

Hej @cabrerahector,

sorry, didn't know where else to categorise this actually. Yeah, that's what I ended up with right now. Don't know if it's best practice but guess will solve it for now at least.

👍

cabrerahector commented 4 years ago

Yeah, I personally don't get why the core endpoint doesn't return the featured image URL either (there's probably a good reason for that but it's unknown to me) but that's how it is. If WordPress ever changes their endpoint so it includes the URL WPP will automatically reflect that change as well.

Anyways, thanks for reporting back. I'm sure this will be useful to others as well. At least as a (temporary) workaround.