'How to get Custom Field data on WPGraphQL
Solution 1:[1]
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
Solution 2:[2]
Try this get all values of category.
get_option( "taxonomy_".$term_id );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Geoff Taylor |
Solution 2 | HatLess |