0

I have stored my site in a cloud backup with localwp. Later I restored this backup into a new site. When I am inside the admin area I can see in the error log that errors are produced when accessing normal admin pages. The actual error is always: WordPress database error Expression #1 of ORDER BY clause is not in SELECT list

Accessing the "Media Library" screen:

[27-Feb-2024 11:22:21 UTC] WordPress database error Expression #1 of ORDER BY clause is not in SELECT list, references column 'local.wp_posts.post_date' which is not in SELECT list; this is incompatible with DISTINCT for query SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
                FROM wp_posts
                WHERE post_type = 'attachment'
                ORDER BY post_date DESC made by wp_enqueue_media
[27-Feb-2024 11:22:21 UTC] WordPress database error Expression #1 of ORDER BY clause is not in SELECT list, references column 'local.t.name' which is not in SELECT list; this is incompatible with DISTINCT for query 
            SELECT DISTINCT t.term_id, tr.object_id
            FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
            WHERE tt.taxonomy IN ('category', 'post_tag', 'post_format') AND tr.object_id IN (127, 124, 122, 64, 62)
            ORDER BY t.name ASC
            
         made by require('wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_object_term_cache, wp_get_object_terms, get_terms, WP_Term_Query->query, WP_Term_Query->get_terms

Accessing the "Posts" screen:

[27-Feb-2024 11:33:48 UTC] WordPress database error Expression #1 of ORDER BY clause is not in SELECT list, references column 'local.t.name' which is not in SELECT list; this is incompatible with DISTINCT for query 
            SELECT DISTINCT t.term_id, tr.object_id
            FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
            WHERE tt.taxonomy IN ('category', 'post_tag', 'post_format') AND tr.object_id IN (127, 124, 122, 106, 70, 66, 64, 62)
            ORDER BY t.name ASC
            
         made by WP_Posts_List_Table->prepare_items, wp_edit_posts_query, wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_object_term_cache, wp_get_object_terms, get_terms, WP_Term_Query->query, WP_Term_Query->get_terms
[27-Feb-2024 11:33:48 UTC] WordPress database error Expression #1 of ORDER BY clause is not in SELECT list, references column 'local.wp_posts.post_date' which is not in SELECT list; this is incompatible with DISTINCT for query SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
                    FROM wp_posts
                    WHERE post_type = 'post'
                    AND post_status != 'auto-draft' AND post_status != 'trash'
                    ORDER BY post_date DESC made by WP_List_Table->display, WP_List_Table->display_tablenav, WP_Posts_List_Table->extra_tablenav, WP_List_Table->months_dropdown

Accessing the "Dashboard" screen:

[27-Feb-2024 11:34:43 UTC] WordPress database error Expression #1 of ORDER BY clause is not in SELECT list, references column 'local.t.name' which is not in SELECT list; this is incompatible with DISTINCT for query 
            SELECT DISTINCT t.term_id, tr.object_id
            FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
            WHERE tt.taxonomy IN ('category', 'post_tag', 'post_format') AND tr.object_id IN (127, 124, 122, 64, 62)
            ORDER BY t.name ASC
            
         made by wp_dashboard, do_meta_boxes, wp_dashboard_site_activity, wp_dashboard_recent_posts, WP_Query->__construct, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_object_term_cache, wp_get_object_terms, get_terms, WP_Term_Query->query, WP_Term_Query->get_terms
[27-Feb-2024 11:34:43 UTC] WordPress database error Expression #1 of ORDER BY clause is not in SELECT list, references column 'local.t.name' which is not in SELECT list; this is incompatible with DISTINCT for query 
            SELECT DISTINCT t.term_id, tr.object_id
            FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
            WHERE tt.taxonomy IN ('category', 'post_tag', 'post_format') AND tr.object_id IN (66, 70, 106)
            ORDER BY t.name ASC
            
         made by wp_dashboard, do_meta_boxes, wp_dashboard_quick_press, wp_dashboard_recent_drafts, get_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_object_term_cache, wp_get_object_terms, get_terms, WP_Term_Query->query, WP_Term_Query->get_terms

It doesn't seem to be affecting anything however. Everything still seems to be running and working.

To me it seems the queries generated by Wordpress are just wrong.

What should I do with these errors?

edit: Corrected wrong version number in the title.

2
  • 1
    Do you mean WordPress 6.x? WordPress 4.3.1 is 5 years old. Feb 27 at 12:56
  • @JacobPeattie I meant to say Wordpress 6.4.3. I don't know how I switched up those numbers.
    – Compjeuter
    Feb 27 at 15:37

1 Answer 1

2

The errors were generated because there was a plugin that forced sql modes to be used on the database that are actually "incompatible" with wordpress.

The following code was sadly executed for every request...

   private function set_sql_mode() : void
    {
        // Make sure no sql modes can be blocked (By wordpress built-in incompatible modes)
        add_filter('incompatible_sql_modes', fn() => [] );

        $this->DB->set_sql_mode([
            'ONLY_FULL_GROUP_BY',
            'STRICT_TRANS_TABLES',
            'NO_ZERO_IN_DATE',
            'NO_ZERO_DATE',
            'ERROR_FOR_DIVISION_BY_ZERO',
            'NO_ENGINE_SUBSTITUTION'
        ]);
    }
2
  • 1
    Can you give an example? I haven't heard of that before. I guess it changed the way names with scopes are interpreted?
    – Rup
    Feb 27 at 23:20
  • I will edit my answer! Thank you.
    – Compjeuter
    Feb 29 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.