gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.23k stars 10.32k forks source link

[gatsby-source-wordpress] Polylang not exposing data as shown in the docs? #13761

Closed MartinConde closed 5 years ago

MartinConde commented 5 years ago

Description

After struggling a little with Gatsby and WPML I thought I'd give Polylang a shot since according to the gatsby-source-wordpress docs, it exposes pretty much everything for every language in a straight forward way.

I am using Polylang Pro(v2.4) and have installed the 'WP REST - Polylang' Plugin

Expected result

I was hoping to query for the same info as shown in the docs like:

...
        polylang_current_lang
        polylang_translations {
          id
          title
          content
          excerpt
          date
          modified
          slug
          author
          featured_media
          template
          polylang_current_lang
        }
...

Basically I would like to query for the slugs of the translations so that I could create a language switcher based on that (if there is a better way do let me know:))

Actual result

I can only query for:

...
        lang
        translations {
          en
          de
        }
...

the language codes under translations return the page ids. polylang_current_lang & polylang_translations aren't there.

Am I missing something or did Polylang change something and doesn't expose that data anymore?

Environment

System: OS: macOS 10.14.4 CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz Shell: 5.3 - /bin/zsh Binaries: Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node Yarn: 1.15.2 - /usr/local/bin/yarn npm: 6.4.1 - ~/.nvm/versions/node/v10.13.0/bin/npm Browsers: Chrome: 74.0.3729.131 Firefox: 66.0.3 Safari: 12.1 npmPackages: gatsby: ^2.3.33 => 2.3.33 gatsby-image: ^2.0.40 => 2.0.40 gatsby-plugin-manifest: ^2.0.29 => 2.0.29 gatsby-plugin-offline: ^2.0.25 => 2.0.25 gatsby-plugin-react-helmet: ^3.0.12 => 3.0.12 gatsby-plugin-sharp: ^2.0.35 => 2.0.35 gatsby-source-filesystem: ^2.0.32 => 2.0.32 gatsby-source-wordpress: ^3.0.57 => 3.0.57 gatsby-transformer-sharp: ^2.1.18 => 2.1.18

DSchau commented 5 years ago

@MartinConde this is an incredibly challenging one to diagnose, because we'd need to configure a project exactly as you specified with Wordpress, which is not a trivial endeavor.

Would you be able to grant us access to your source code and the Wordpress instance so we could take a look for ourselves? Feel free to DM on Twitter or e-mail me (dustin [at] gatsbyjs [dot] com).

Thank you!

MartinConde commented 5 years ago

@DSchau Thanks a lot for jumping in so fast :D I've sent you the logins etc via mail. I tried using a fresh install on the server and a local one as well and it was the same. Also I tried downgrading the WP Version just in case but didn't do anything either. Lastly I tried messing with permalinks and the whitelisted routes inside gatsby-config.js

Here is the repository: https://github.com/MartinConde/GatsbyWpPolylang

Thanks a lot again!

MartinConde commented 5 years ago

@DSchau Figured it out. Should have thought about trying this way sooner haha. Using the free version of Polylang, everything works as expected. I guess since the Pro version has it's own functionality to expose some stuff to the REST API there is some conflict with the WP REST - Polylang Plugin.

lexcode commented 5 years ago

Hi @MartinConde I am having the exact issue, using the Polylang Plugin ( free version ). Did you solve it by buying the PRO version then?

image

MartinConde commented 5 years ago

@lexcode Actually I only had the issue when using the pro version, using the free version everything worked fine. I think your error might be a different one, do you have a repo up with the full code?

I ended up just switching back to wpml again and passing the ID of the translation through context, then using that id to query the path of the translated page and passing that value all the way back up to the Language Switcher.

lexcode commented 5 years ago

I got it sorted yesterday @MartinConde, by using the polylang free version + wp-rest-polylang

Cheers!

hidaeraldo commented 5 years ago

I am having the same problem . When I query like the doc shown all i get is that "can not query polylang_current_lang ", even when i try the query of example here same response for lang and translations . These are the plugins i have installed in wp . image

MartinConde commented 5 years ago

@hidaeraldo you also need the polylang rest plugin: https://github.com/maru3l/wp-rest-polylang as mentioned here: https://www.gatsbyjs.org/packages/gatsby-source-wordpress/#wordpress-plugins

hidaeraldo commented 5 years ago

@MartinConde once i install polylang rest plugin as you mentioned up here and mentioned in docs , I can no more query from my WordPress , it changes the query to static folder , like https://github.com/gatsbyjs/gatsby/issues/12801 also here isn't a response This is a view of how my graph ql look when I install polylang rest plugin image And this is the view before i installed it image

wardpeet commented 5 years ago

Are you sure the rest api is giving you the correct information?

hidaeraldo commented 5 years ago

@wardpeet that is the problem , the rest api that comes to query isn't the right, Don't know , maybe it is making a conflict with others plugin , but i am not find what is really causing that problem, In the other hand the json of word press is okay but the graph is showing problems

zamson commented 4 years ago

Sorry to hijack a thread about Polylang but @MartinConde can you please post an example on how to create the page nodes for WPML. I'm having trouble with this since WPML translated pages won't show up in graphql. I suspect it might have to do with included routes. Also not really sure how to map the nodes in the best way.

vanmarkic commented 4 years ago

Same here @zamson . Right now I’m actually modifying the wpml rest api plug-in in order to include the content in the wpml translations array. There’s also a pending PR to solve this at Gatsby level

dannyvaughton commented 4 years ago

For anyone wanting to use Polylang Pro + gatsby-source-wordpress:

I have slightly modified @maru3l's wp-rest-polylang to enable the same fields.

See: https://github.com/dannyvaughton/wp-rest-polylang-pro

northpeakdigital commented 1 year ago

hey @dannyvaughton, thanks for this. So what would an example graphql query to retrieve polylang translated pages look like?