Multiple order specifications in pre_get_posts do not work according to the spec
-
add_action('pre_get_posts','cs_pre_get_posts'); function cs_pre_get_posts($query) { if (is_admin() || !$query->is_main_query()) { return; } if (!lightning_is_woo_page() && !is_singular() && !is_search() && !is_404()) { $meta_query_args = array( 'relation' => 'OR', 'exists' => array( 'key' => 'プラン', 'compare' => 'EXISTS', ), 'notexists' => array( 'key' => 'プラン', 'compare' => 'NOT EXISTS', ), ); $query->set('meta_query', $meta_query_args); $query->set( 'orderby', array('exists' => 'desc', 'notexists' => 'desc', 'date' => 'desc') ); } }
I am trying to use the above code to display articles with custom field plans saved in priority and those that are not saved are moved to the back of the list, but it does not work.
So I check the contents of $query, check the SQL query and run it directly from phpmyadmin and I get the following error.
(1055): Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'local.wp_postmeta.meta_value' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
This seems to be an error that occurs when sql_mode=only_full_group_by is enabled, but I can find an article that basically says it should not be turned off.
Is this a problem with the WordPress specification?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Multiple order specifications in pre_get_posts do not work according to the spec’ is closed to new replies.