Im trying to order a wp_query by meta_value
Im using the following arguments
array(
'post_type' =>'event',
'posts_per_page' => -1,
'meta_query' => array(
'dates_query' => array(
'key' => 'dates',
'value' => date(time()),
'compare' => '>='
)
),
'orderby' => 'dates_query',
'order' => 'ASC',
'paged' => 1
);
This is the request that is generated by wp_query
SELECT wp_posts.* FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE 1=1 AND ( ( wp_postmeta.meta_key = 'dates'
AND wp_postmeta.meta_value >= '1514960717' ) )
AND wp_posts.post_type = 'event'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'completed'
OR wp_posts.post_status = 'acf-disabled')
GROUP BY wp_posts.ID
ORDER BY CAST(wp_postmeta.meta_value AS CHAR) ASC
Unfortunatly the results are wrong and when trying to execute the query manualy im getting the following error:
Expression #1 of ORDER BY clause is not in GROUP BY clause and contains non-aggregated column
I know there is an option to disable "only_full_group_by" but im wondering if that is the best practice in this case
Thanks