2

I'm setting up a Gatsby site that pulls data from an existing wordpress site that I host on my own server [Dreamhost].

After I set up the plugin according to the docs and when I run 'gatsby develop', this happens. No data object is returned.. the plugin I installed on the wordpress site seems to do nothng.

=START PLUGIN=====================================

Site URL: https://example.com

Site hosted on Wordpress.com: false

Using ACF: false

Auth: false

Verbose output: true

Mama Route URL: https://example.com/wp-json

⡀ source and transform nodes

Path: /wp-json

The server response was "404 Not Found"

error Plugin gatsby-source-wordpress returned an error

TypeError: Cannot read property 'data' of undefined

====================================================

I have the https://github.com/WP-API/Basic-Auth installed and activated.. and indeed, no /wp-json.

What am I missing?

I feel like the issue is with my WP-API plugin or Wordpress settings.

*the example.com is used for privacy sake in the above

Thanks in advance, Jason

Sfili_81
  • 2,377
  • 8
  • 27
  • 36
honeymkr
  • 21
  • 3
  • Is `baseUrl` inside the `gatsby-source-wordpress` config options set to your WordPress URL or to `example.com`? Can you access https://example.com/wp-json (replace with your WP site's URL) in your browser? You shouldn't need any authentication set up to access `/wp-json` – lightstrike Nov 27 '18 at 17:44
  • Yep, my baseUrl is set to my Wordpress URL. mysite.com/wp-json gives me 404. The Wordpress site is installed at /dev on the server. I've tried mysite.com/dev/wp-json with no luck, also dev.mysite.com/wp-json just for the heck of it and got 404. – honeymkr Nov 28 '18 at 05:22
  • @honeymkr have you found a solution for this problem ? I'm running the same one. – Uj Corb Jan 14 '19 at 14:36

2 Answers2

1

Got the solution here.

I also faced similar problem in a local project. I used index.php after my project url and it worked. http://localhost/myproject/index.php/wp-json/wp/v2/posts

Try to access [yourwordpresssite.com]/index.php/wp-json/ and see if it works.

If yes then go to gatsby-config.js and ammend restApiRoutePrefix:"index.php/wp-json"

0

I talk about using gatsby-source-wordpress in a series at https://www.iamtimsmith.com/blog/how-to-build-a-blog-with-wordpress-and-gatsby-part-1/.

If you can see some json at mysite.com/dev/wp-json/wp/v2/pages then the problem lies within a query in the Gatsby project. If you can't get to a json object at mysite.com/dev/wp-json/wp/v2/pages then the problem lies within the WordPress installment and Gatsby can't find the rest api.

Tim Smith
  • 56
  • 2