Reputation: 543
Using gatsby-source-wordpress I have a content type called 'student' which has a ACF relationship field that links to content type 'posts'. I want to show the related posts (title and other fields) on the student page.
On a student post i can get various fields of the related content, wordpress_id seems most useful (below is an example of the ACF relationship field on a 'student' set to show 'wordpress_id's:
{
"node": {
"acf": {
"related_projects": [
64,
88,
1
]
}
}
}
What i'd like to do is construct a graphQL query on the student page the selects all posts that match enter code here
a set of wordpress_ids. I can see how to match a single id, but not multiple. Or can a single graphQL query be looped over on a page?
Upvotes: 4
Views: 753
Reputation: 11
If you're using the ACF to REST API plugin on your WordPress site, then you can query related posts added via an ACF Relationships field.
Here is a GraphQL query example using a Flexible Content layout field called Related Content and a ACF relationship field called Related Posts:
{
allWordpressPost {
edges {
node {
title
acf {
content_post {
__typename
... on WordPressAcf_related_content {
related_posts {
post_title
post_content
}
}
}
}
}
}
}
}
Upvotes: 0