Created
July 5, 2019 17:25
-
-
Save jasonbahl/d2dfe0c56390e9c9c8b0c25d7d6c4bd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'graphql_post_object_connection_query_args', function( $args ) { | |
$args['no_found_rows'] = false; | |
return $args; | |
} ); | |
add_filter( 'graphql_connection_page_info', function( $page_info, $connection ) { | |
$page_info['total'] = null; | |
if ( $connection->get_query() instanceof \WP_Query ) { | |
if ( isset( $connection->get_query()->found_posts ) ) { | |
$page_info['total'] = (int) $connection->get_query()->found_posts; | |
} | |
} | |
return $page_info; | |
}, 10, 2 ); | |
add_action( 'graphql_register_types', function() { | |
register_graphql_field( 'WPPageInfo', 'total', [ | |
'type' => 'Int', | |
] ); | |
}); |
Should we use wp-graphql-offset-pagination Plugin over this?
I was also looking for this solution and added into a simple plugin - you can use it
wp-graphql-nexgi-extension
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where do we need to add this script? Thanks!