I have to make a search form where i have to populate a select by the states of custom posts types. Some of them have the same state, then I would like to group-by to have a
You can try below code:
postmeta . '.meta_key = "state"';
}
?>
'observatoire',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'state'
));
?>
Query Look like:
SELECT wp_posts.*
FROM wp_posts INNER JOIN wp_postmeta
ON (wp_posts.ID = wp_postmeta.post_id)
WHERE wp_posts.post_type = 'observatoire'
AND (wp_posts.post_status = 'publish')
AND (wp_postmeta.meta_key = 'state' )
GROUP BY wp_postmeta.meta_key = "state"
ORDER BY wp_posts.post_date DESC