admin管理员组文章数量:1289541
I have created a custom post type (jobPosts).
I'm using Gatsby/Graphql/Apollo to query and mutate data.
Problem: I need to grab job posts from Wordpress to for a specific user.
I would like to query the jobPosts by 'author', but the Graphiql interface does not give me the option to use 'where' with 'author' (it doesn't exist in the scheme?):
Desired query:
`{
query getJobs($userId: Int!) {
jobPosts (where: {author: $userId}) {
edges {
node {
id
databaseId
jobPostFields {
title
sector
}
}
}
}
}
}`
Does anyone know how to add this functality to the schema / add 'author' to the '(where:{})' filter? Or another way to get this filtered data, without having to pull all the job posts and using something expensive like data.filter()?
Thanks for your time!!
I have created a custom post type (jobPosts).
I'm using Gatsby/Graphql/Apollo to query and mutate data.
Problem: I need to grab job posts from Wordpress to for a specific user.
I would like to query the jobPosts by 'author', but the Graphiql interface does not give me the option to use 'where' with 'author' (it doesn't exist in the scheme?):
Desired query:
`{
query getJobs($userId: Int!) {
jobPosts (where: {author: $userId}) {
edges {
node {
id
databaseId
jobPostFields {
title
sector
}
}
}
}
}
}`
Does anyone know how to add this functality to the schema / add 'author' to the '(where:{})' filter? Or another way to get this filtered data, without having to pull all the job posts and using something expensive like data.filter()?
Thanks for your time!!
Share Improve this question asked Jul 13, 2021 at 9:08 Joseph Pilgrim GlaisherJoseph Pilgrim Glaisher 11 bronze badge 3 |1 Answer
Reset to default 1You'll need to add support for the author when you create your custom post type.
Make sure that you add to your supports array so it's similar to this:
"supports" => array( "title", "editor", "author" ),
This will allow your GraphiQL to have that data!
You MAY need to go back to each post and re-save them though as they don't have any author data until you do!
本文标签: Graphql Unable to query (whereauthor) for custom post type
版权声明:本文标题:Graphql: Unable to query (where:{author}) for custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741431235a2378373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
"supports" => array( "title", "editor", "author" )
– rudtek Commented Jul 13, 2021 at 14:21