Skip to content

Instantly share code, notes, and snippets.

@jkhaui
Last active March 8, 2022 08:39
Show Gist options
  • Save jkhaui/b91517dda66dc84ec3deaaa4edd9a63f to your computer and use it in GitHub Desktop.
Save jkhaui/b91517dda66dc84ec3deaaa4edd9a63f to your computer and use it in GitHub Desktop.
add_action( 'graphql_register_types', function() {
register_graphql_field( 'Hashtag', 'hashtagImg', [
'type' => 'String',
'description' => __( 'The image (URL) for a topic.', 'wp-graphql' ),
'resolve' => function( \WP_Term $term ) {
$topic_meta = get_term_meta( $term->id, '_topic_image', true );
$img_post = wp_get_attachment_url( $topic_meta );
return ! empty( $img_post ) ? $img_post : null;
}
] );
} );
@munishd8
Copy link

munishd8 commented Mar 8, 2022

// Add Votes to Custom Meta Fields add_action( 'graphql_register_types', function() { register_graphql_field( 'case_study_type', 'section_tree', [ 'type' => 'String', 'description' => __( 'Casestudy Section Tree', 'wp-graphql' ), 'resolve' => function( \WP_Term $term ) { $sectiononecontent = get_term_meta($term->term_id , 'section_tree', true); return ! empty( $sectiononecontent ) ? $sectiononecontent : 0; } ] ); } );
Post Type : case_study
Taxonomy Type : case_study_type
code is not working can you please help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment