• I am using the Gigs Calendar plugin for a DJ website. Rather than the plugin’s standard table of events, I am using a WP_Query call to display all posts with Category_name=Events .Works great except I need to sort them in according to the show date. The date is the first thing in the title. See here

    Here is the template page code

    <?php
    /*
    Template Name: Events
    */
    ?>
    <?php get_header(); ?>
    	<div id="content">
        <div class="post-inner">
    
    <?php
    $loop = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 10 , 'category_name' => 'Events' ));  
    
    	?>
    	<?php while ( $loop->have_posts() ) : $loop->the_post(); 
    
    ?><h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_title();?></a></h2><?php	
    
    	the_content ();
    
    	endwhile;?>
    	<?php // do_shortcode ('[gigs-calender archive]');?>
    	        </div><!-- #content -->
    	        <?php if (have_posts()) :
    	while (have_posts()) : the_post();
    	the_content ();
    	endwhile;
    	endif;
    ?>	        </div>
    
    <?php get_sidebar();?>
    <?php get_footer(); ?>

    I’m thinking something along the lines of reading the initial string of the title, converting it to a date, then resorting the WP_Query but not sure how to do it. Can anyone help? Would also like to have a divider for events that have already happened.

  • The topic ‘Advanced Post Sorting’ is closed to new replies.