I'd like to receive the blog title of my wordpress blog via a graphql query to use it in my gatsby page, but I can't figure how to do it. A GET Request to /wp-json on the REST-API gives this information pretty easily, but how do I query for it with GraphQL using the plugin?
Hi @openmedi, please check the source code of using-wordpress example.
Hey @kakadiadarpan the blog title is not read out using gatsby-source-wordpress in this example: Title and subtitle is defined in gatsby-config.js and then used in /src/templates/page.js and /src/templates/post.js. But it's not actually received from the wordpress blog itself.
Or am I reading that wrong?
P. S.: Note that I'm looking for a way to get the title of the blog, not posts or pages. I know how to get the later.
cc @pieh
I'm not sure but probably wordpress plugin doesn't expose that information now. If anyone would like implement that - here's where to start:
https://github.com/gatsbyjs/gatsby/blob/b3bab8edd7d790a6a15706fe0076691ca02164ac/packages/gatsby-source-wordpress/src/fetch.js#L73 Here we are hitting main REST endpoint - and for now we use that only to get list of available endpoints - but we could use that response to extract site metadata (such as site name, description, url and home if linked stackexchange answer is correct) and create new entity with wordpress site metadata - so few lines below change
https://github.com/gatsbyjs/gatsby/blob/b3bab8edd7d790a6a15706fe0076691ca02164ac/packages/gatsby-source-wordpress/src/fetch.js#L78
to something like
let entities = [
{
__type: 'wordpress__site_metadata',
siteTitle: <grab_data_from_response>,
[... any other available metadata]
}
]
Which would later automatically should then later make querying in graphql possible:
{
wordpressSiteMetadata {
siteTitle
}
}
I'm looking into this now myself. 馃
@openmedi Please ping me if you get stuck or need any help
@pieh I just made a PR concerning this.
Hi @openmedi, do you have an example of this?
Most helpful comment
I'm not sure but probably wordpress plugin doesn't expose that information now. If anyone would like implement that - here's where to start:
https://github.com/gatsbyjs/gatsby/blob/b3bab8edd7d790a6a15706fe0076691ca02164ac/packages/gatsby-source-wordpress/src/fetch.js#L73 Here we are hitting main REST endpoint - and for now we use that only to get list of available endpoints - but we could use that response to extract site metadata (such as site name, description, url and home if linked stackexchange answer is correct) and create new entity with wordpress site metadata - so few lines below change
https://github.com/gatsbyjs/gatsby/blob/b3bab8edd7d790a6a15706fe0076691ca02164ac/packages/gatsby-source-wordpress/src/fetch.js#L78
to something like
Which would later automatically should then later make querying in graphql possible: