I create a section of the sidebar of events in which only the next 3 events will be displayed. I have a custom message type and custom fields, everything works, but I can figure out how to sort messages by the start date of events, which is a custom field value. Is there a php function that can compare dates and arrange them in a specific order. I think that he would also have to save the identifier after the new dates, so that when reading the values ββI could display the corresponding post with this date.
Does anyone have a specific direction to guide me?
I think this is what I need to do:
- Read messages and take dates
- Sort dates with post-id associated with these dates.
- Read the sorted dates and redisplay the first 3 posts by id
I get lost on how to code this, though ... This is what I still have. This code simply displays them by publication date in wordpress.
<?php query_posts('post_type=events'); if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $dateStart = get_post_meta($post->ID, 'date-start', true);?> <div class="date"><?php echo $dateStart; ?></div> <?php endwhile; endif; wp_reset_query(); ?>
source share