Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Dennis Eitner
Full Stack JavaScript Techdegree Graduate 25,593 PointsHow do I apply a sort order to a wordpress loop if the sortby is a custom field (acf) and has the format "dd.mm"?
I am trying to get post order to be sorted by date (custom field). But when I apply sort order, it does sort but only by days, not by date.
$dateformatstring = "m.d.y"; $date = strtotime(get_field('datum'));
$args = array ('post_type' => 'events', 'meta_key' => $date, 'orderby' => 'meta_value_num', 'order' => 'ASC' );
2 Answers

Kelvin Atawura
Front End Web Development Techdegree Student 19,022 PointsCan you explain further on your question. so you are trying to sort it by dates and days. Do you want the date and days to appear on the post? is thats the case you can use $latest and then pull out the publish information associated with the post. if l have totally get it all wrong then do explain further.
Also i would say read the wordpress codex and use less PHP hard code in your wordpress dev as you would make things harder for yourself. Use the appropriate wordpress php functions and that.

Dennis Eitner
Full Stack JavaScript Techdegree Graduate 25,593 PointsHi Kevin. Thanks for your answer. I would like to sort a custom post type with custom fields by date. I have the following fields:
Date of event Time Title The Content.
The tricky part for me is to get the right sort order for the date format. I (european date: dd.mm). Right now it sort only for the days. So 29.02 is higher than 05.04. I am a little stuck here.
Thanks for you help.