Custom Fields and PHP the_date
-
Ok, so I’m using custom fields to add “event dates” for upcoming events on a blog. First let me say I’m not looking for plugin suggestions, they’re all bloated and complex.
I have a sidebar with a custom loop that runs like this
<?php $recentPosts = new WP_Query(); $recentPosts->query('showposts=5meta_key=event_date&orderby=meta_value&category_name=events&order=ASC'); if ($recentPosts->have_posts()) : while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li><?php if((get_post_meta($post->ID, "event_date", true))) { ?><span class="event_date"> <?php echo get_post_meta($post->ID, "event_date", true); ?> <?php } ?> <!-- END event_date --></span> <a class="event_title" href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; else: ?> <li><?php _e('No upcoming Events'); ?></li> <?php endif; ?>
The trouble that I have is that when I sort by the custom field “event_date” naturally it sorts my ‘Feb 08’, ‘Mar 28’, etc. dates alphabetically. Is there a way to somehow embed date information in these custom fields so that I can have real dates and use PHP the_date to call them as ‘M d’ in one place and ‘m D, Y’ in another?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Fields and PHP the_date’ is closed to new replies.