Sort Posts By Custom Field Date?
-
I have the following code displaying varying posts from a few different categories, however i need them displayed in date order from information put in a custom field, can this be done?
However, i am using a custom write panel; will this have a baring..
<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; $postcnt = 0; query_posts('cat=3,4,5,6&order=desc'); $lastPost=$wp_query->post_count; if (have_posts()) { echo '<div class="example">'; echo '<ul class="content_cols">'; while ( have_posts() ) : the_post(); $postcnt++; $data = get_post_meta( $post->ID, 'key', true ); $category = get_the_category(); echo'<li class="cat'.$category[0]->cat_ID.'">'; echo '<a href="'; the_permalink(); echo '" title="View more details of '; the_title(); echo '"><img src="wp-content/uploads/'; echo $data[ 'event_image' ].'" alt = "work image"/></a>'; echo '<h3>'; the_title(); echo '</h3>'; echo '<p>'.$data[ 'event_date' ].'</p>'; echo '<p>'.$data[ 'event_location' ].'</p>'; echo '<p>'.$data[ 'event_time' ].'</p>'; echo '<p><a href="'; the_permalink(); echo '" title="View more details of '; the_title(); echo '">Read More</a></p>'; echo '<div class="clearFix"><!--x--></div>'; echo '</li>'; //if the post was the 6th if($postcnt % 6 ==0) { //close the list, add the line,clear the float and close the div echo '</ul>'; if($postcnt != $lastPost) { //lastPost contains the total number of posts //only display the line div if this is not the last line of posts echo '<div class="line"></div>'; } echo '<div class="clearFix"><!--x--></div>'; echo '</div>'; //if the post was not the last if($postcnt != $lastPost) { //lastPost contains the total number of posts //create a new example div and list echo '<div class="example">'; echo '<ul class="content_cols">'; } } endwhile; ?> </ul> <div class="clearFix"><!--x--></div> <?php } ?>So idelly they are presented in order of the custom field
<?php echo $data[ 'event_date' ]; ?>which i have set up.How can i add that info at the top of the loop so it displays in date order and how would the date have to be written in the custom field?
Can it even be done?
Many thanks for any help, it would be brilliant π
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
The topic ‘Sort Posts By Custom Field Date?’ is closed to new replies.