You're running into an issue with MySQL's ONLY_FULL_GROUP_BY mode
, which enforces strict grouping rules. The error happens because MySQL requires all selected columns that are not part of an aggregate function (like COUNT()
, SUM()
, etc.) to be included in the GROUP BY
clause.
Why Is This Happening? Your query includes:
ORDER BY wp_postmeta.meta_value ASC;
Since wp_postmeta.meta_value is not included in the GROUP BY clause, MySQL complains that it can't determine a single value for ordering.
How to Fix It?
If GROUP BY wp_posts.ID
is not strictly necessary, you can remove it. Try modifying your function like this:
if ( 'anyx-training' === $query['post_type']) {
$query['meta_key'] = "anyx-training-order";
$query['orderby'] = "meta_value_num";
$query['order'] = "ASC";
$query['suppress_filters'] = false; // Ensures WP_Query doesn't suppress the meta query
}
return $query;
}
add_filter( 'query_loop_block_query_vars', 'training_qv_anyx_training', 10, 2 );