wordpress-gatsby-preview-starter
wordpress-gatsby-preview-starter copied to clipboard
Can't create pages for new custom post type
I tried to create a new custom post type, using any of the plugins that are out there.
For example, Custom Post Types UI.
I named it category. After that, I created a new script inside /site/gatsby
(createCategoryPosts.js), and changed all the beers or beer occurrences to categories and category.
I get this error:
I tried restarting both docker and yarn, without any change or success.
What could be the problem?
Thanks
The error you are posting would indicate that the category post type does not exist or doesn't have a title or URI. What happens when you query the WordPress endpoint directly?
Hi again.
I would get a JS at the CategoryTemplate
componente because postData
would be undefined, so the destructuring would throw an error:
const postData = props.preview ?
props.preview.categoryBy.revisions.nodes[0] :
props.data.wpgraphql.category
const {
title,
content,
} = postData;
However, I have news.
I ended up changing post-type.php
so it would work for category
instead of beer
.
In the beginning, this wouldn't work either (same error), until I lowercased these lines:
'graphql_single_name' => 'category',
'graphql_plural_name' => 'categories',
And restarted docker. I don't know which one of these 2 actions fixed it but now everything works and the new categories that I create become available upon restarting the yarn process, both through preview and "normal" access, so to say.
However, I have another question.
query GET_POSTS($first:Int $after:String){
wpgraphql {
categories(
first: $first
after:$after
) {
pageInfo {
endCursor
hasNextPage
}
nodes {
id
uri
categoryId
title
}
}
}
}
I don't understand why these wpgraphql queries don't show up at the endpoint http://localhost:3030/graphql
.
I use Altair as a GUI to see all the possible queries, and I can't find it there.
If I use a Custom Post Type plugin to create it, and then create a few elements inside it, this query returns undefined.
Why can I only query the custom post types created in post-type.php
?
Where can I play with that wpgraphql
query?
Thanks