wp-graphql-wpml icon indicating copy to clipboard operation
wp-graphql-wpml copied to clipboard

Querying Options Pages

Open Ninodevo opened this issue 5 years ago • 15 comments

Is it possible to query option pages (created with ACF) in different languages?

Ninodevo avatar Nov 19 '20 13:11 Ninodevo

I am not sure what you mean by option pages.

rburgst avatar Nov 20 '20 07:11 rburgst

https://www.advancedcustomfields.com/resources/options-page/

Admin option pages.

Ninodevo avatar Nov 20 '20 08:11 Ninodevo

I figured out how to make this work. I'll make a fork

Ninodevo avatar Nov 20 '20 09:11 Ninodevo

PRs are always welcome!

rburgst avatar Nov 20 '20 09:11 rburgst

@Ninodevo how did you solve getting Option pages from all languages?

simongoot avatar Feb 23 '21 08:02 simongoot

@simongoot I've created a CPT "option pages" and had them translated I didn't manage to get ACF Options Pages in other languages

Ninodevo avatar Feb 23 '21 08:02 Ninodevo

Any progress on getting options pages translated @rburgst ?

simongoot avatar Jun 24 '21 15:06 simongoot

I'm hoping someone made some progress on this since. Would it be possible to add a "where" argument to options page queries like they exist for custom post types? That way, one could query the options given a specific language.

Ririshi avatar Jan 11 '23 12:01 Ririshi

Really need this functionality. Any progress/solution?

akkis avatar Feb 01 '23 12:02 akkis

I'm trying to make this work in a fork. There don't seem to be any hooks in the WP GraphQL for ACF code to hook into the options pages anywhere. I tried to add a wpmlLanguage argument to each options page field, by deregistering and re-registering the options pages fields. This doesn't work because the fields seem to lose their ACF group resolvers (which are programmatically registered after the options page fields are), so all fields inside a group return null when using this method.

If anyone can help to come up with a working fix, that'd be appreciated. My next step / attempt will be to try to manually register all options pages again and then run the code from WP GraphQL for ACF to add the groups to the options page fields.

https://github.com/Ririshi/wp-graphql-wpml/commit/74e0c6ba86a5c0c3a5a46478139b01867032b778

Ririshi avatar Mar 21 '23 12:03 Ririshi

Imho unregistering Graphql fields won’t achieve a lot. You need to see how the data is loaded within WordPress and what wpml is doing to prevent all options to appear. Then you need to check whether there is a way to prevent wpml from doing that. Typically this is done by overwriting some wpml state variables. this is why debugging and trying to implement features like this is so very tedious and time consuming.

rburgst avatar Mar 21 '23 13:03 rburgst

Normally, the query for an options page returns only one page, there is no way to return all options pages at once. So each of those queries returns one page, in the default language. My goal is to add an argument to each of those queries, and use the argument to change the active language in WPML / sitepress. At least for my usecase, it should function similarly to PR https://github.com/rburgst/wp-graphql-wpml/pull/32.

Ririshi avatar Mar 22 '23 09:03 Ririshi

I just managed to solve this issue, quite simply. The issue I encountered previously was caused by me missing a line of code that sets the type of the options page to "options_page", while registering the options page fields again. I created a PR https://github.com/rburgst/wp-graphql-wpml/pull/42. Hoping it can be merged quickly with a tag version bump, so we can use the official package in our project :)

Ririshi avatar Mar 22 '23 11:03 Ririshi

For those who need this functionality, you can use this branch on my fork until the PR is accepted.

Ririshi avatar Apr 04 '23 13:04 Ririshi

+1

Seabon avatar Apr 13 '23 09:04 Seabon