• Resolved Richard

    (@rgenck)


    I am using Toolset to manage my custom content, I need their Views functionality, and am using the following code snippet to call the custom fields associated with that content into posts into GraphQL:

    <?php
    add_action( 'graphql_register_types', function() {
        register_graphql_field( 'SupportCall', 'summary', [
           'type' => 'String',
           'description' => __( 'Call summary', 'wp-graphql' ),
           'resolve' => function( $post ) {
             $summary = get_post_meta( $post->ID, 'wpcf-summary', true );
             return ! empty( $summary ) ? $summary : $summary;
           }
        ] );
      } );

    I am able to query single posts, but not multiple posts, which I need to make a posts list. Is there a setting I need to change, or something I need to add to the code to retrieve multiple posts? Or do I need a totally different code snippet?

Viewing 1 replies (of 1 total)
  • Plugin Author Jason Bahl

    (@jasonbahl)

    @rgenck the $post that comes through the resolve function is an instance of a WPGraphQL Post Model, not a WP_Post object.

    So instead of get_post_meta( $post->ID, ... ) you would want to do get_post_meta( $post->databaseId, ... )

    See if that works?

Viewing 1 replies (of 1 total)
  • The topic ‘Can query single post type, not multiple’ is closed to new replies.