I know there are a lot of articles and documentation on this but I can’t seem to figure it out.
I have a custom post type ‘agenda’ wich is made for events.
I want to sort this by the eventdate.
For this, I made a custom field (datepicker) using the ACF plugin.
I’ve found some documentation on the ACF website wich learned me how to echo the date in dutch format and also an article about sorting the posts by custom meta value.
But I can’t get it to work.
The key for my custom field is: datum_agenda
Codes I have already tried ( in the $args of the loop):
'orderby' => 'datum_agenda'
&
'meta_key' => 'datum_agenda',
'orderby' => 'meta_value_num',
'order' => 'DESC'
What am I doing wrong here?
Seems like my code can’t seem to find my meta_key or something because it still sorts by the autovalue.. (the normal post date)
Your second approach should in my mind actually work, you do it like this:
Code:
There are two pages at the ACF documentation you might want to read: Date Picker and Order posts by custom fields. Besides that the only thing that comes to mind would be how is the date formated and might the problem originate there, having
yymmdd
as value for the ACF »Date Picker« field »Save format« is recommended.