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

Fix pagination conflict with the “Post Type Order” plugin

When using the Post Type 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_posts which fires when WP_Query is executing.

This then checks to see if the request is a GraphQL request and whether Post Types Order plugin class is available as a global. If these conditions are not met, nothing happens. If these conditions are met, we carry on.

Next, we remove the “posts_orderby” filter from the Post Types Order plugin, as it was overriding WPGraphQL’s ordering which is needed for cursor pagination to work properly.

Then, we add our own filter back to WPGraphQLs Post Object Connection query args and set the orderby to be menu_order => 'ASC'