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
  • did you add support for author when you created the cpt? "supports" => array( "title", "editor", "author" ) – rudtek Commented Jul 13, 2021 at 14:21
  • This solved it thanks! – Joseph Pilgrim Glaisher Commented Jul 20, 2021 at 13:42
  • awesome. I posted as an answer below. Could you check it as correct? – rudtek Commented Jul 20, 2021 at 14:44
Add a comment  | 

1 Answer 1

Reset to default 1

You'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