Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
🔧 Fixes errors regarding ONLY_FULL_GROUP_BY when using WordPress with managed database services using MySQL 8.
Plugin Name: WP Managed MySQL 8 Fix
Plugin URI:
Description: Fixes issues regarding MySQL modes (ONLY_FULL_GROUP_BY) when on managed database services.
Author: Matheus Pratta
Version: 1.0.0
Author URI:
add_action('init', 'wp_fixes_mysql8_full_group_by', -1);
function wp_fixes_mysql8_full_group_by () {
global $wpdb;
// Parse all our current modes
$currentModes = explode(',', array_pop($wpdb->get_results('SELECT @@sql_mode'))->{'@@sql_mode'});
// Find the offending index (ONLY_FULL_GROUP_BY)
$removeIndex = array_search('ONLY_FULL_GROUP_BY', $currentModes);
// If found, unset it
if (false !== $removeIndex) unset($currentModes[$removeIndex]);
// Sets the SQL mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment