Php Wordpress custom fields - sort by date in a query using GROUP_CONCAT

Asked

Viewed 47 times

1

Good afternoon,

My question is perhaps complicated and perhaps it is impossible to do what I want, I apologise in advance.

I am building a website in Wordpress avoiding resorting to plugins, which brings me here.

In order to have available a schedule of events, where sometimes the same event repeats in several days or on the same day at different hours I created in the articles a custom field (day|time|local|who|type), where the user puts the day, time, place, who and type separated by "|", for example "26/09/2020|16:00|children’s sports park|masc|Atl"

What I want is to select from the database all these events for each article, BUT order them soon by date increasingly

use

SELECT CONCAT(post_id) AS Post, GROUP_CONCAT(meta_value, '|sep|') AS Datas FROM wp_postmeta WHERE post_id = '" . $id_do_post -> post_id . "' AND meta_key = 'dia|hora|local|quem|tipo' GROUP BY post_id

I get almost what I want, but events appear in order of entry

array (
0 => 
(object) array(
   'Post' => '2933',
   'Datas' => '26/09/2020|12:00|parque municipal|iniciados masc|atl|sep|,25/09/2020|14:00|parque municipal|infantis|atl|sep|,26/09/2020|18:00|centro de dia|seniores|universidade senior|sep|',
),

)

The question is, is there any way to do this query to get the dates sorted, 25/09 to 14h, then 26/09 to 12h and finally 26/09 to 18h? And yet another question, it will also be possible to determine which of the dates is the nearest and add to the array 'Mais_proxima' => '25/09/2020 ?

Thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.