Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Dennis Eitner](https://secure.gravatar.com/avatar/277e251f2f6b415f423fcf7d365e0a0b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dennis Eitner
Full Stack JavaScript Techdegree Graduate 25,644 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](https://uploads.teamtreehouse.com/production/profile-photos/102016/micro_codepen.jpg)
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](https://secure.gravatar.com/avatar/277e251f2f6b415f423fcf7d365e0a0b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dennis Eitner
Full Stack JavaScript Techdegree Graduate 25,644 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.