I’m developing a plugin and I have made a CPT for events and it has custom fields (one of the fields is for the date).
Everything works fine, Fields and CPT are working and displaying them on the front end works also. But the problem is I can’t order my CPT posts by date from the custom field called date_happening.
I have tried to find answer to my problem in many articles, but all of the articles point to the same solution which I tried but for some unknown reason doesn’t work for me.
I provide here code.
This is how I create custom fields for my cpt.
And this is what many articles told me how my query arguments should look like to order events by custom field values.
I have also tried to use ‘meta_value_date’, ‘meta_value_num’ etc but without any success.
But if I change order values from ‘DESC’ to ‘ASC’ then all my posts will come in opposite order so it seems like it’s querying by post_date value and completely ignores my args except ‘order’ argument.
I have also checked how the date_happening field value is saved in the database table wp_postmeta and it seems to be in good format.
I hope everything was understandable and I would appreciate if anyone could help me.