Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[source-wordpress] Avoiding Error 404 on built-in endpoints #1649

Open
maxyudin opened this issue Aug 23, 2022 · 0 comments
Open

[source-wordpress] Avoiding Error 404 on built-in endpoints #1649

maxyudin opened this issue Aug 23, 2022 · 0 comments

Comments

@maxyudin
Copy link

Sometimes some WordPress basic REST endpoints may be hidden from view by a plugin or theme.

To have control over which endpoints to load data from and to avoid fetch fail due 404 error when loading data, it might be a good idea to add something like this to gridsome.config.js:

plugins: [
  {
    use: '@gridsome/source-wordpress',
    options: {
      loadPostTypes: true,
      loadUsers: true,
      loadTaxonomies: true,
      loadPosts: true,
    }
  }

And to WordPressSource class constructor() (index.js):

api.loadSource(async actions => {
  this.store = actions

  console.log(`Loading data from ${baseUrl}`)

  if (options.loadPostTypes) {
    await this.getPostTypes(actions)
  }
  if (options.loadUsers) {
    await this.getUsers(actions)
  }
  if (options.loadTaxonomies) {
    await this.getTaxonomies(actions)
  }
  if (options.loadPosts) {
    await this.getPosts(actions)
  }

  await this.getCustomEndpoints(actions)
})

I'm sure the code could be more elegant and is meant to be adjusted by somebody more experienced than me.

Is it even a good idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant