1

我正在使用GraphiQL来测试我的自定义帖子类型是否正在添加到 GraphQL。

排名显示在我的 WP-Admin 导航中,我可以添加/编辑/删除项目,因此我知道 CPT 正在工作。但是我看不到它GraphiQL

函数.php

new Common\PostType\RankingsPostType;

Common/PostType/RankingsPostType.php

class RankingsPostType extends PostType
{
public $postTypeOptions = [
'taxonomies' => ['user\_category'],
'show\_in\_rest' => true,
'supports' => ['title', 'author', 'editor', 'comments']
];


public function init()
{
    parent::init();
    $this->registerGraphQLType();
}

public function registerGraphQLType()
{
    add_action( 'graphql_register_types', function() {
        register_graphql_field( 'RankingsPostType', 'color', [
            'type' => 'String',
            'description' => __( 'The color of the post', 'wp-graphql' ),
            'resolve' => function( $post ) {
                $color = get_post_meta( $post->ID, 'color', true );
                return ! empty( $color ) ? $color : 'blue';
            }
        ] );
    } );
    add_action( 'init', function() {
        register_post_type( 'RankingsPostType', [
            'show_ui' => true,
            'labels'  => [
                'menu_name' => __( 'Docs', 'RankingsPostType' ),//@see https://developer.wordpress.org/themes/functionality/internationalization/
            ],
            'show_in_graphql' => true,
            'hierarchical' => true,
            'graphql_single_name' => 'Ranking',
            'graphql_plural_name' => 'Rankings',
        ] );
    } );
}

这不是您register_post_type在我的 PostType 中注册的地方吗?

4

0 回答 0