I’m not super-familiar with the loop yet…
But, can you try this?
query_posts( array (
'post_type' => 'agenda_item',
'meta_key' => more_fields("agenda-datum"),
'orderby' => 'meta_value',
'order' => 'DESC'
) );
That should work, but the dates have to be stored in the database as YYYYMMDD, like
20130809
The SQL query won’t see dates, but rather string values, so you have to use structure the dates like that.
Then:
<?php
while(have_posts()) : the_post();
// get the date
$date= more_fields('agenda-datum');
// convert to Unix timestamp, then reformat, then print result
echo date(strtotime('M d Y', $date));
// above prints ex. Aug 09 2013
With my first try I got this:
13-3-2014
1-12-2014
13-8-2013
1-12-2013
With your hint I got this:
13-3-2014
1-12-2014
1-12-2013
13-8-2013
While I want to get this:
1-12-2014
13-3-2014
1-12-2013
13-8-2013
Yes! Christian1012 you sir are a gentlemen, with your hint I got it to work. I ended up storing the dates in the database the way you said, and it worked fine. Thanks a lot!
Hi there i saw the post and it looks like the seems to offer the solution but I still can’t figure it out. I’m having the same problem here!
Before reading the post i had my code as below
<?php
$post_meta_data = get_post_custom($post->ID);
if( !empty($post_meta_data['SHOM_available_date'][0]) ) {
$av_date = $post_meta_data['SHOM_available_date'][0];
echo '<small> Available After '.$av_date.' </small>';
}
?>
And I made the changes to store the field as YYYYMMDD on custom meta_box
and on the DB they are store as YYYYMMDD after changed the above to:
<?php
$post_meta_data = get_post_custom($post->ID);
if( !empty($post_meta_data['SHOM_available_date'][0]) ) {
$av_date = $post_meta_data['SHOM_available_date'][0];
echo date(strtotime('M d Y', $av_date));;
}
?>
After changing it doesn’t echo at all!!
Does anyone have any idea?
Resolved by changing to this:
<?php
$post_meta_data = get_post_custom($post->ID);
if( !empty($post_meta_data['SHOM_available_date'][0]) ) {
$av_date = $post_meta_data['SHOM_available_date'][0];
echo '<small> Available After ';
echo date("M d Y", $av_date);
echo '</small>';
}
?>
Thnx for the post to all