1

I've been working on this website event page

http://aishaarab.com/events/

everything is working but I have 2 problems:

  1. I can't get it to only show upcoming event meaning when an event is past to not shoe it or not display it.
  2. When I output the post_meta onto my page using <?php meta('event-end-date'); ?> my result format is 08-12-2014 i would like the month to be letters like this august 12, 2014.

here is code:

<ul class="event_list_view">    

<?php // Let's get the data we need to loop through below
//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$d = date("m-d-Y");
$today = date('Y-m-d', strtotime('-6 hours')); //define "today" format; note timezone offset of -6 hours
$args = array(
    'post_type' => 'event',
    'posts_per_page' => '3',
    'post_status'  =>  'publish',
    'meta_key' => 'event-start-date',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'meta_query' => array(
    'relation'  =>   'AND',
    array(
            'key' => 'event-end-date',
         'meta-value' => date('Y-m-d', strtotime('-6 hours')), //value of "order-date" custom field
         'compare' => '>=', //show events greater than or equal to today
         'type' => 'CHAR'
        )
    )
);
$the_query = new WP_Query( $args ); ?>


<?php if ( $the_query->have_posts() ) : ?>

    <!-- pagination here -->

    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>





<li class="clearfix">
<div class="featured_tag"></div>


<?php if ( '' != get_the_post_thumbnail() ) { ?>
<a class="post_img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail('event-thumbnail'); ?>
</a>
<?php } else { ?>
<a class="post_img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="http://aishaarab.com/wp-content/uploads/2014/08/DefaultEvent-125x75.png" alt="" />
</a>
<?php } ?>

<h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>

<p class="timing"> 
<span>Start Date: </span><?php meta('event-start-date'); ?><br>
<span>End Date: </span><?php meta('event-end-date'); ?><br>
<span>Time: </span><?php meta('event_time'); ?><br>
</p>

<p class="address"><span>Location :</span> <br><?php meta('event_address'); ?>, <?php meta('event_city'); ?>, <?php meta('event_state'); ?>, <?php meta('event_country'); ?></p>
<div class="clear"></div>
<p class="bottom">
<a class="read_more" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Read More</a>
</p>

</li>


    <!-- #post-<?php the_ID(); ?> -->

     <?php endwhile; else: ?>  
      <p> 
        <?php _e('Sorry, no events matched your criteria.'); ?>  
      </p>  
      <?php endif; ?> <?php //wp_reset_query(); ?>


</ul>
  • is event-end-date meta value contain time in unix time stamp or in formated time string ? – Ravinder Kumar Aug 17 '14 at 22:03
  • please share your code for meta() function, it's helps us to check that what value you are printing from this function. – Ravinder Kumar Aug 17 '14 at 22:06
  • i'm using the more fields plugin and its a text post_meta field used for the event-start-date and event-end-date which is entered as 07-12-2014 – frenchy black Aug 17 '14 at 22:18
  • @Ravs i edited the code to this now <?php $d = date("m-d-Y"); $args = array( 'post_type' => 'event', 'posts_per_page' => '3', 'post_status' => 'publish', 'meta_key' => 'event-start-date', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'meta_key' => 'event-start-date', 'value' => time(), 'compare' => '>=' ) ) ); $the_query = new WP_Query( $args ); ?> – frenchy black Aug 17 '14 at 22:21
1

your are comparing time against wrong time string:

change:

'meta-value' => date('Y-m-d', strtotime('-6 hours')), //value of "order-date"

to this

'value' => date('m-d-Y', strtotime('-6 hours')), //value of "order-date"

because your time string is in m-d-Y format and you are check against Y-m-d which is wrong.

NOTE

if above trick doesn't work then i suggest you to store time in unix time stamp in database. please read these links for more info how to do it and why

  1. https://designhammer.com/blog/sorting-events-date-using-wordpress-custom-post-types
  2. http://www.billerickson.net/code/create-a-unix-timestamp-based-on-two-meta-fields/
  • updated code per your request but still now working <?php $args = array( 'post_type' => 'event', 'posts_per_page' => '3', 'post_status' => 'publish', 'meta_key' => 'event-start-date', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'event-end-date', 'meta-value' => date('m-d-Y', strtotime('-6 hours')), //value of "order-date" 'compare' => '>=', //show events greater than or equal to today 'type' => 'CHAR' ) ) ); – frenchy black Aug 17 '14 at 22:44
  • code updated, change meta-value to value under meta_query – Ravinder Kumar Aug 17 '14 at 22:47
  • same thing it output all the events but the first event of 2013 is still there but the weird thing i added a future event for 2015 that dont show. – frenchy black Aug 17 '14 at 23:05
  • answer updated, please read link which i mentioned. – Ravinder Kumar Aug 17 '14 at 23:15
  • thank you after reading both links, i went into the more fields plugin and instead of using the text field for the date i use the built-in html5 date field and now its working perfectly, thank you – frenchy black Aug 18 '14 at 6:22

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.