Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Query taxonomy term inside ACF Repeater field #16

Closed
elvismdev opened this issue Jul 10, 2019 · 7 comments · May be fixed by #89 or #262
Closed

Query taxonomy term inside ACF Repeater field #16

elvismdev opened this issue Jul 10, 2019 · 7 comments · May be fixed by #89 or #262

Comments

@elvismdev
Copy link

Hi,

I have an ACF Repeater field, with different types of fields inside of it. One of them is a WordPress Taxonomy, for which I cannot find how to return the values of the terms on it, it keeps returning just empty [] values.

Here some screenshots to illustrate my ACF fields setup.

Screen Shot 2019-07-09 at 5 16 41 PM

Screen Shot 2019-07-09 at 5 17 00 PM

Here my query and the results from GraphQL, where it returns empty values for the taxonomy Indicator, despite that in my query I'm requesting their taxonomy ID and name.

Screen Shot 2019-07-09 at 5 19 47 PM

Screen Shot 2019-07-09 at 5 19 52 PM

What I'm missing here?

@jasonbahl
Copy link
Contributor

Thanks for reporting with such detail. I’ll look into this tomorrow and follow up.

@elvismdev
Copy link
Author

If this helps for more context, I moved the taxonomy out of the Repeater field, like to make it be just a standalone Taxonomy type field in ACF, and got the same results.

Screen Shot 2019-07-09 at 9 14 04 PM

Screen Shot 2019-07-09 at 9 14 14 PM

After this last attempt that makes me think (in case this is a bug) that this is not related with having the Taxonomy type field nested inside a Repeater ACF field. It looks like wp-graphql/wp-graphql-acf currently is not capable to query the Taxonomy terms from ACF.

Because for the record, querying this Taxonomy the regular way it does returns the terms values as expected.

Screen Shot 2019-07-09 at 9 33 13 PM

Screen Shot 2019-07-09 at 9 33 23 PM

@jasonbahl
Copy link
Contributor

@elvismdev I'm looking into this now.

@elvismdev
Copy link
Author

Thanks @jasonbahl !

jasonbahl added a commit that referenced this issue Jul 23, 2019
# Conflicts:
#	vendor/composer/autoload_static.php
@henrikwirth
Copy link
Collaborator

@jasonbahl I have the same Issue with Taxomony-Fields inside a Flexible Content layout

@henrikwirth
Copy link
Collaborator

Okay so the problem I had with taxonomies was actually a different one. I didn't get all the pages with all the childPages and therefore the childPage with the taxonomy field wasn't available.

@jasonbahl
Copy link
Contributor

I believe this issue comes from how WPGraphQL Core loaded terms in hierarchical taxonomies.

For a while, WPGraphQL Core's loader would load only top level terms with parent=>0, and you had to explicitly ask for children.

In the case of this ACF field, the underlying query ended up being something like:

$query = new WP_Term_Query( [
  'include' => [ 1, 2, 3 ]
  'parent' => 0
] );

And let's say terms 2 and 3 were child/grandchild.

This query would return just term 1, because it's the only one with parent => 0.

This was fixed in WPGraphQL core and from my testing this seems to be working in WPGraphQL for ACF now.

Current

Current behavior with:

  • WPGraphQL v1.3.8
  • WPGraphQL for ACF v0.5.2
  • ACF Pro v5.9.4

I can set the value of a taxonomy field in a repeater with a top-level term and a grandchild term and get these terms in the response:

Screen Shot 2021-05-13 at 1 08 24 PM

Upcoming v0.6.0

In the upcoming v0.6.0 release, the shape of the query changes a bit to respect the post->terms connection better, but the functionality of returning related terms whether they are top-level or children, remains.

Screen Shot 2021-05-13 at 1 01 27 PM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants