-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gatsby-source-wordpress] Get (flexible content) fields for multiple post types #8615
Comments
Can you create fragment for flexible content type instead of fragments for each types that can be used? |
@pieh I'm not sure what you mean. What I'm trying to do is create one fragment that can be used for all types. In the example above it's called Fragment per typeAnother option would be to create "fragments" per flexible content type, as such for two types of blocks:
And then per content type:
This would make the 'per type' part quite verbose (and not DRY), especially when you have 5 or 10 content types who all benefit from this flexible content field. It would still be very easy to 'forget' adding this to all 5-10 types when you create a new type of flexible content block. Would there be any way of making this non-repetitive, since we always need to change this when the content types change? |
What about something like: fragment ContentType on <NameOfContentFieldType> {
__typename
... on WordPressAcf_text {
fields
}
... on WordPressAcf_image {
fields
}
} and then wordPressWpPage {
title
maybeAnotherField
acf {
content {
...ContentType
}
}
} |
Yes, that would be great and is exactly what I've been poking around with. However, I cannot find |
Ah, you are right of course. Unfortunately there is way of doing this right now, so you need to do this as You are doing right now :/ We plan on adding more control for users for schema generation (so you could force type name for |
Okay, that's too bad. Thanks for your quick response however. Theoretically, would it be an idea to 'share' |
This was fixed in #9052. Thanks again for your help @pieh! You can now use this notation: #8615 (comment), where |
I think there are no issues opened on this subject, so here it goes.
Summary
I want to query flexible content fields from a WordPress post type. Using the provided link, this is quite easy. I just use a query similar to this (simplified without using variables for retrieval):
Now let's say I have a load of different field types, making this query quite long. Now, the same fields are used on several post types. They have (some) different fields, but all have the same 'flexible content' field. I want to query them all in the same way, so I don't have to copy and paste this long list of flexible content types for all post types. On the React side of things, the same component that handles the different blocks is used.
Ideally, the query would look something like this:
The obvious solution would be using a fragment. Something like this:
However, this fragment would only work for the type
wordpress__wp_post
and the fieldcontent_post
. Is there any way to make this fragment's content dynamic? String interpolation seems impossible for GraphQL queries.Maintaining a 'static' fragment per type would seem quite impossible for 10+ field types, especially when creating new ones. I've looked into a bunch of options, but I cannot seem to find the right approach. Is this possible and does anyone have a great tip on where to start?
Relevant information
Environment (if relevant)
File contents (if changed)
gatsby-config.js
: N/Apackage.json
: N/Agatsby-node.js
: N/Agatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: