Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
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 Answer 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«.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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