sergiodxa/react-wordpress

Not working on WP API v2

Closed this issue · 2 comments

Hi, @sergiodxa,
I've forked your project and changed the constant baseURL to work with the WP API v2 and it doesn't work. You can see it at https://github.com/freecates/react-wordpress.
Can you help me? The error says: Cannot read property 'sort' of undefined.
Thanks.

You may have already figured this out by now, but the syntax in v2 is slightly different. I've gotten this to work:

in libs/api.js, update to:
const baseUrl = "https://public-api.wordpress.com/wp/v2";

in pages/index.js, update to (I had to remove posts from the object):
const [ site, posts ]

Also, be sure to check your json from /wp/v2. It's a little different as well. For example, in components/Post.js, update to:
{post.title.rendered}
and
{post.excerpt.rendered}

Hope this helps. And if someone who's reading this knows of a better way to write this, let me know!

@freecates hi, I'm not really maintaining this repo, it was just an idea I coded and pushed but not something I'm actually using to keep an interest in maintaining it.