WordPress.org

Ready to get started?Download WordPress

Forums

Order loop by custom field date (4 posts)

  1. pdruk
    Member
    Posted 2 months ago #

    Hi there
    I'm struggling to work out how to sort the list below into order by custom field 'date_start' - to output a list of "coming soon" shows per theatre that are in the correct date order. The web page is:
    www. westendtheatre.com/category/theatres
    cheers

    <?php
    $today = date('Y-m-d');
    
    # COMING SOON QUERY
    $args = array('cat' => 12, 'meta_key' => 'theatre_id', 'meta_value'	=> $post->ID, 'meta_query' =>array
    ('relation' => 'AND',
    array('key' => 'date_start', 'value' => $today, 'compare' => '>' ), 		), );
    
    $the_query = new WP_Query($args);
    ?>
    
    <?php if($the_query->have_posts() ) : ?>
    <div class="headlineexcerpt3" style="display:inline;">
    Coming Soon:
    <ul>
    <?php // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    $showid = $the_query->post->ID; ?>
    
    <li><a href="<?php the_permalink();?>"><?php echo get_post_meta($showid, 'showname',1); ?></a></li> 
    
    <?php endwhile; wp_reset_postdata(); ?>
    </ul>
    </div>
    <div style="clear:both;"></div>
    <?php endif;//COMING SOON query?>
  2. hiphopinenglish
    Member
    Posted 2 months ago #

    What does your code currently output?

  3. pdruk
    Member
    Posted 2 months ago #

    It outputs a list of shows playing at the theatre, but orders them by post date, not by my custom field "date_start"
    cheers

  4. hiphopinenglish
    Member
    Posted 2 months ago #

    You'll need to use Order parameters in WP_Query.

    Try:

    'meta_key' => 'date_start',
    'orderby'  => 'meta_value',

    In your query.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.