简体   繁体   中英

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

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.

在此处输入图片说明

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

在此处输入图片说明

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.

在此处输入图片说明

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

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

在此处输入图片说明

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

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM