0

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?):

enter image description here

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!!

3
  • did you add support for author when you created the cpt? "supports" => array( "title", "editor", "author" )
    – rudtek
    Jul 13, 2021 at 14:21
  • This solved it thanks! Jul 20, 2021 at 13:42
  • awesome. I posted as an answer below. Could you check it as correct?
    – rudtek
    Jul 20, 2021 at 14:44

1 Answer 1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.