Homepage
Link to WPGraphQL on Github
Link to WPGraphQL on WordPress.org

Fix pagination conflict with the “Advanced Taxonomy Terms Order” plugin

When using the Advanced Taxonomy Terms Order plugin along with WPGraphQL, you might experience some issues with paginated queries.

This snippet should help correct the conflict:

What this snippet does:

First, this hooks into pre_get_terms which fires when WP_Term_Query is executing to get Terms out of the database.

This checks to see if the request is a GraphQL request and whether Term Order plugin is active. If these conditions are not met, nothing happens.

If these conditions are met, we carry on.

Next, we remove the “terms_clauses” filter from the Terms Order plugin, as it modifies the SQL statement directly, after WPGraphQL has determined how to map order args to SQL.

Then, we add our own filter back to WPGraphQLs Term Object Connection query args and set the order and orderby arguments here. This ensures that the order will be properly mapped to WPGraphQLs cursor pagination logic.