2

I have created events as custom post types and I'm storing the event start date as a custom field (YYYY-mm-dd). I've also assigned a taxonomy to each event.

I need to display a list of events by category in a single month.

The code below shows that I am currently able to display a list of events by the taxonomy 'bmx racing' but I now need to display all the bmx racing events in any given month.

I need to work out how to take the month from the event start date (custom field) and apply it to this query.

<?php
query_posts( array(
'post_type' => 'event',
'event-category' => 'bmx racing'
'posts_per_page' => '-1', 
    'orderby' => 'date',
    'order' => 'ASC',
     ) );
  if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

  <h3 style="color:#99cc00;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  <?php the_content(); ?>

<?php endwhile; endif; wp_reset_query(); ?>

Any help is much much appreciated.

Thanks in advance

  • Is there anyone that can help with this, I'm still struggling to display custom posts types within a date range. – Brad May 3 '12 at 15:36
1

Do a simple meta_query and compare by meta_value_num.

array(
    'post_type' => 'webcast',
    'meta_key'  => 'webcast-date',
    'meta_value'    => array( time(), strtotime('+60 days') ),
    'meta_type'     => 'numeric',
    'meta_compare'  => 'BETWEEN',
    'orderby '  => 'meta_value_num',
    'order'     => 'ASC'
);

For an easy example. You can find more complex examples on the site filed under - even more if you combine that with a search for »meta_value_num date«.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.