WPGraphQL: Custom Post Types query using SLUG as unique identifier returns no data

Viewed 701

I've created a Custom Post Type in WordPress named "projects" and now I'm trying to query a single project using the slug as an identifier. In other words, I want the idType to be the SLUG, not ID. I tried the following query but it does not work.

enter image description here

However, this query works (it's a common query that is using the ID) :

enter image description here

The query above is not what i'm looking for, but at least i know that my CPT is registered correctly and that my data can be fetched somehow.

Why I think this is a problem? Because I used the same type of query for querying WordPress posts (not custom posts types, just posts) and it works fine. I'm being returned the correct data.

enter image description here

Any help is appreciated ;) I don't know if i'm missing something with my query, or if custom post types don't work the same way that posts do.

WPGraphQL version: 1.3.10 Other WordPress plugins installed: Advanced Custom Fields, Custom Post Type UI

1 Answers

Set the idType to URI. Here's an example, querying a page (it's the same for other post types as well):

enter image description here

NOTE: the GraphiQL IDE has some nice auto-completions and drop-downs to show the available options:

enter image description here

My understanding is the idType:SLUG option is not available when your custom post type is hierarchical since the slug would not be a unique identifier at that point.

Related