1

I create a new field in Custom Fields and give it a location, like this:

enter image description here

After that I activate the Show In GraphQL button and set acf name:

enter image description here

Now, I'm trying to make a query for acf globalOptions in wp-graphql and it gives me an error. Moreover, I can't find globalOptions either in suggestions or in the schema.

GraphiQL-IDE: playground

Docs:

schema

How could I fix this problem?

Thanks in advance.

Syscall
  • 19,327
  • 10
  • 37
  • 52
  • without location? – xadm Mar 16 '21 at 09:08
  • what do you mean 'without location'? Should I delete or choose something different? – Daniel Barbakadze Mar 16 '21 at 09:54
  • you used this term – xadm Mar 16 '21 at 10:35
  • I used it because of the pic, I mean Rules that define where to show selected acf – Daniel Barbakadze Mar 16 '21 at 10:54
  • how it (location) is (can be) related to graphql API ? – xadm Mar 16 '21 at 10:56
  • 1. Creating acf gives me the possibility to create new fields in acf. 2. Setting rules give me the possibility to show those fields in Global Options and upload real data. 3. Plugin `WPGraphQL for Advanced Custom Fields` gives me the possibility to add acfs to the graphql scheme. 4. If I'm right, after that I could be able to query those fields from graphql IDE. Where do I make a mistake? – Daniel Barbakadze Mar 16 '21 at 11:12
  • Options PAGE != global options ? there is no PAGE in API context – xadm Mar 16 '21 at 11:24
  • `Advanced Custom Fields PRO` contains Global Options that generate this rule automatically. – Daniel Barbakadze Mar 16 '21 at 11:28
  • so what is the solution, how can I approach my aim? I just want to query global options in graphql (p.s other acf queries work) – Daniel Barbakadze Mar 16 '21 at 11:37
  • and this is not related to `/wp-admin/options-general.php` ? screen and page terms in rule means nothing? ... I don't think it's graphql type related ... probably (didn't read ACL docs about that) you have to use `register_graphql_field` to 'manually' extend graphql `globalOptions` type – xadm Mar 16 '21 at 11:42
  • I've already added in `functions.php` this peace of code: `if (function_exists('acf_add_options_page')) { acf_add_options_page(array( 'page_title' => __('Global Options'), 'menu_title' => __('Global Options'), 'autoload' => true, )); }` Do you mean this in registering 'manually'? – Daniel Barbakadze Mar 16 '21 at 12:02

1 Answers1

3

The problem was in a file functions.php:

it was like:

acf_add_options_page(array(
    'page_title' => __('Global Options'),
    'menu_title' => __('Global Options'),
    'autoload' => true,
));

But it should be like:

acf_add_options_page(array(
    'page_title' => __('Global Options'),
    'menu_title' => __('Global Options'),
    'autoload' => true,
    'show_in_graphql' => true
));

I was missing the 'show_in_graphql' => true key:value pair.

  • hmmm, I have to check these options ... key name is taken from titles? is lang/translation related? `graphql_single_name` or `graphql_plural_name` can be used? ... you can accept your own answer – xadm Mar 16 '21 at 19:52
  • I can accept my answer after one day. The key name is taken from GraphQL Field name and after that, you are able to make a query like `globalOptions { acfGlobalOptions { //...} }`. What do you mean by a single or plural name, btw? – Daniel Barbakadze Mar 17 '21 at 09:30
  • single/plural are params for CPT used by wp-graphql plugin, used to define root keys like `post` and `posts` ... in this case it could (if works) be used to rename `globalOptions` key name - define it independently, not related to menu/page [translated] title – xadm Mar 17 '21 at 09:49
  • I think it's single because hierarchy is like globalOptions > acfGlobalOptions > [ array of fields defined in acfGlobalOption]. Also in `Rules`, I have only one (selected) option. – Daniel Barbakadze Mar 17 '21 at 13:27
  • probably ... but ... is it (`'globalOptions'` key name) changeable with `graphql_single_name` param ? – xadm Mar 17 '21 at 13:30
  • I think yes, by changing `page_title` and/or `menu_title` key values in `functions.php` – Daniel Barbakadze Mar 17 '21 at 13:36
  • ... but ... with `graphql_single_name` instead [of possibly translated titles] ? – xadm Mar 17 '21 at 13:39
  • I tried both(`single` nad `plural`) but has no affect. `page_title`([see img](https://i.stack.imgur.com/3fcrX.png)) value changing causes Rule's last select field name's changing – Daniel Barbakadze Mar 17 '21 at 15:06
  • Thank you too ;) If that helped you please thumbs up my answer, I'll be so grateful – Daniel Barbakadze Mar 18 '21 at 11:49