wp-graphql / wp-graphql-tax-query

Adds `tax_query` support to postObject connection queries using WP_Query
46 stars 16 forks source link

Feature/advice request: Make taxQuery argument available on post object when inside an acf relationship field. #22

Open mjwlist opened 3 years ago

mjwlist commented 3 years ago

Hi I'm not really sure if this should be asked here or here https://github.com/wp-graphql/wp-graphql-acf/issues as this relates to both, or at least combining both.

I would like to know if it is possible to add the taxQuery to posts that are added within the acf relationship field so they can be queried in the same way as the post itself.

EG: On posts or custom post types etc it is fantastic to query as follows:-

query{ posts(where: {taxQuery: {taxArray: {field: SLUG, operator: IN, taxonomy: SOME_CATEGORY, terms: "some-term"}}}) { edges { node { id } } } }

What I need to achieve is to have the same taxArray filtering options available on posts added within an acf relationship field.

EG: Take the following query on an acf relationship field:-

query{ someCustomPostType(where: {name: "some-name"}) { nodes { id content_relations { content { ... on Post { id } ... on CustomPost { id } } } } }

Is there any possibility of making the taxQuery available on the content node?? Something like the following:-

query{ someCustomPostType(where: {name: "some-name"}) { nodes { id content_relations { content(where: {taxQuery: {taxArray: {field: SLUG, operator: IN, taxonomy: SOME_CATEGORY, terms: "some-term"}}}) { ... on Post { id } ... on CustomPost { id } } } } }

You might wonder why not just query the two or more post types directly which of course would work just fine. The single benefit of doing with the relationship field it to be able to set the order of the posts in the response. Thats it.

Any thoughts, ideas, advice greatly appreciated. This is something I really need to implement somehow.