jkhaui
1/3/2019 - 8:33 AM

term_meta.php

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;
       }
    ] );
  } );