0

How to get Custom Field data on WPGraphQL

I add a custom field for upload featured image for category. Now I want to get this value on WPGraphQL Query.

How to get Custom Field data on WPGraphQL

enter image description here

Raju Ahammad
  • 873
  • 2
  • 9
  • 15

2 Answers2

3

You still have to register your custom field to the GraphQL schema using the register_graphql_field() function.

add_action( 'graphql_register_types', function() {
    register_graphql_field( 'PostCategory', 'categoryImage', [
        'type' => 'MediaItem',
        'resolve' => function( $post ) {
            $image = get_post_meta( $post->databaseId, 'category_image_id'  );
            return ! empty( $image ) ? $image : null;
        }
    ]);
});

Reference the WPGraphQL custom field recipes for more info here

Geoff Taylor
  • 496
  • 3
  • 17
-1

Try this get all values of category.

get_option( "taxonomy_".$term_id );
HatLess
  • 10,622
  • 5
  • 14
  • 32