wordpress-gatsby-preview-starter icon indicating copy to clipboard operation
wordpress-gatsby-preview-starter copied to clipboard

Can't create pages for new custom post type

Open Richacinas opened this issue 4 years ago • 3 comments

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:

Captura de pantalla de 2020-10-27 10-49-59

I tried restarting both docker and yarn, without any change or success.

What could be the problem?

Thanks

Richacinas avatar Oct 27 '20 09:10 Richacinas

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?

justinwhall avatar Oct 27 '20 14:10 justinwhall

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.

Richacinas avatar Oct 27 '20 15:10 Richacinas

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

Richacinas avatar Nov 04 '20 15:11 Richacinas