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 need to list the next seven days no matter what day it is. If its monday, it starts with today and lists 7 days, if its friday it starts with today and lists 7 days from today.

Next I need to show any events for that day. IF there are no events for a given day it simply lists a default graphic.

I am going to make a featured event for a each day and eventually set it up so that it just shows that one but for now I just want to list the next 7 days and any events contained within them.

I have two piece that don't fit together very well. First:

<?php $cur_day = 'current_day'; $last = 'last';
$date = date('o-m-d'); $ts = strtotime($date); $dow = date('w', $ts); 
for ($i=0; $i<7; $i++, $ts+=86400){ ?>

This will list each of the next 7 days starting with today.

 $event_query = new WP_Query(
        array( 
          'post_type'   => 'event',        // only query events
          'meta_key'    => 'event-date',  // load up the event_date meta
          'orderby'     => 'meta_value',
          'order'       => 'asc',         // ascending, so earlier events first
          'meta_query'  => array(
             array(         // restrict posts based on meta values
              'key'     => 'event-date',  // which meta to query
              'value'   => $event_date,  // value for comparison
              'compare' => '=',          // method of comparison
              'type'    => 'NUMERIC'         // datatype, we don't want to compare the string values
            ) // meta_query is an array of query ites
           ) // end meta_query array
          ) // end array
        ); // close WP_Query constructor call

This lists the next seven days but doesn't do well with the events...

I am looking to duplicate this: http://www3.dmagazine.com/events with cpt's

thanks PLEASE HELP

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You should definitely do it in just a single query. then set up a simple loop, each iteration get that day's date. then loop through all posts and compare the date to the date meta field, and output if it matches. I think something like this should work...

$today = date("o-m-d");
$future = strtotime ( '+6 days' , strtotime ( $today ) ) ;
$future = date ( 'o-m-d' , $future );
$event_query = new WP_Query(
    array( 
      'post_type'   => 'event',
      'meta_key'    => 'event-date',
      'orderby'     => 'meta_value',
      'order'       => 'asc',
      'meta_query'  => array(
         array(
          'key'     => 'event-date',
          'value'   => array($today,$future),
          'compare' => 'BETWEEN',
          'type'    => 'DATE'
        )
       )
      ) 
    );

for ($i=0; $i<7; $i++){
    $thedate = strtotime ( '+'.$i.' day' , strtotime ( $today ) ) ;
    $thedate = date ( 'o-m-d' , $thedate );
    echo $thedate;
    // loop thru all posts and check $thedate against your date meta
    // and output if it matches
    // then rewind_posts(); to set it up for the next day
}
share|improve this answer
    
So the initial QP_Query is getting all the events that fit between today and the 7 days from now. Then if I hear you right, I need to run a simple query_posts loop inside of the for loop that is currently echoing the dates and compare $thedate to event-date. IS that what you have in mind? –  TJ Sherrill Jun 6 '11 at 14:18
add comment

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.