Gatsby: How can i fetch users or authors from my blog posts with gatsby-source-wordpress?

Created on 12 May 2019  路  7Comments  路  Source: gatsbyjs/gatsby

Hi folks, i've created a new project for my blog webpage in gatsby.js using the gatsby-source-wordpress for fetching the blog posts from my account in wordpress.com. Everything is well until i've notices when i get some data from 'allWordpressPost' or 'wordpressPost' these queries include the 'author' field to refer to the author of the post, but i can't find something else that help me to retrieve the name or email fields from this author or user.

My question is. Have some queries for get this additional data from the authors of the posts? I pretend in a future include other people to write posts in my site, then i'll need some ways to retrieve additional data from them.

I've been searching in the docs, for some samples to get data from the users but i've can't find that.

question or discussion

All 7 comments

@StevensCol Tried querying the 'author' field in GraphiQL and it has numerous subfields in it, including "id" and "name". In my case the name field actually returned the email address, but that may be simply because I didn't fill in my name on wordpress.

Here's the snippet you can try:

author {
      id
      name
    }

@orshick thanks for answering. I've tested this on my query but i got this error:

error GraphQL Error Field "author" must not have a selection since type "Int" has no subfields.

My query is:

query {
    allWordpressPost {
      totalCount
      edges {
        node {
          date
          path
          title
          excerpt
          author {
            id
            name
          }
          jetpack_featured_media_url
        }
      }
    }
  }

My wordpress-source-plugin config:

{
      resolve: `gatsby-source-wordpress`,
      options: {
        baseUrl: `stevenscol306757988.wordpress.com`,
        protocol: `https`,
        hostingWPCOM: true,
        verboseOutput: false,
        useACF: false,
        includedRoutes: [
          '**/posts',
          '**/tags',
          '**/users'
        ]
      }
    }

@StevensCol Ah, you're pulling the date from a wordpress.com site. I don't have any experience doing this, but trying it out just now, the author field did indeed return an integer.

The plugin's documentation says you need to provide additional authentication if sourcing from a wordpress.com site, so the user information is likely simply hidden until you provide the appropriate authentication information.

@orshick that was the problem! Thank you, i've put the auth data in gatsby-config.js and this works fine. Now the question is, When i trying to get the id from author or post this give me the internal id from graphql, how can i get the real id from the data?

@StevensCol try including wordpress_id in your graphql query, I think that'll return what you want.

@lightstrike works pretty wll! thank you. Why these topics dont appear in the docs? Is very frustrating :(

I've found this on http://localhost:8000/___graphql :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ferMartz picture ferMartz  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

benstr picture benstr  路  3Comments