• Resolved Lobsterdm

    (@lobsterdm)


    We have three events displayed on the home page of the site which are ordered to date ascending (so to display the next three dates) but it looks like the code ignores any events where there’s a time entry for the date so the only events displayed are those where a time is missing. So we get three events in ascending order but not necessarily the next three events.

    Here is the code that displays the events. Have I missed something?

    
    <div class="events_section">
    
    <div class="wrapper">
    
    <div class="events_inner">
    
    <?php $args = array(
    'posts_per_page'   => 3,
    'offset'           => 0,
    'category'         => '',
    'orderby'          => 'event_date',
    'order'            => 'ASC',
    'include'          => '',
    'exclude'          => '',
    'meta_key'         => '',
    'meta_value'       => '',
    'post_type'        => 'event',
    'post_mime_type'   => '',
    'post_parent'      => '',
    'post_status'      => 'publish',
    'suppress_filters' => true ); ?>
    <?php $posts_array = get_posts( $args ); 
    //echo '<pre>';
    //print_r($posts_array);
    ?> 
    
    <?php foreach($posts_array as $event)
     {?>
    
    <div class="events_blk">
    
    <div class="events_blk_inner">
    
    <h2><?php echo $event->post_title; ?></h2>
    
    <h4><?php the_field('event_date', $event->ID);?></h4>
    
    <p><?php echo wp_trim_words( $event->post_content,20) ?></p>
    
    <a>ID); ?>">More info here.</a>
    
    </div>
    
    </div>
    <?php }?>
    <p>*Like to schedule an author event at your school, library, bookstore, or conference? <a>/author-visits/">Visit this page</a>.</p>
    
    </div>
    

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Guido

    (@guido07111975)

    Hi,

    Time field is a regular text input, so this field is not being used to determine how the events are ordered. I might change this in an upcoming version, because several users requested this.

    When I take a look at your code, I notice you aren’t ordering on meta_key… For upcoming events I’m using the event start date for this:

    
    'meta_key' => 'event-start-date',  
    'orderby' => 'meta_value_num',  
    

    Source code can be found here.

    Please take a look at this plugin file for the query I’m using.

    Guido

    (I’ve added tag modlook because the code is messy, guess you forgot to click the [code] button before and after your code)

    • This reply was modified 6 years, 5 months ago by Guido. Reason: have updated my reply
    Thread Starter Lobsterdm

    (@lobsterdm)

    That worked a treat thank you

    Plugin Author Guido

    (@guido07111975)

    Great. I’m marking this thread as resolved.

    But I wonder why you don’t simply use the events shortcode (or the widget) on the homepage… with some custom CSS to customize the layout to your needs?

    Guido

    Thread Starter Lobsterdm

    (@lobsterdm)

    Hi Guido,
    Thanks for your help previously. Just another question if I may… we have this line in the code that seems to refer to a custom field type the original developer added but it’s not outputting an event date and time.

    What would I need to change it to so that I can output the start date and time?

    <h4><?php the_field(‘event_date’, $event->ID);?></h4>

    Russ

    Plugin Author Guido

    (@guido07111975)

    Hi,

    That’s an old one, the first releases of my plugin contained 1 single date only.

    Because my plugin uses a start-date and end-date, it’s not that easy to display “the event date” anymore.

    That’s why I wonder why you aren’t using the shortcode or the widget for this, and customize it’s layout to your needs using custom CSS?

    Guido

    Plugin Author Guido

    (@guido07111975)

    Hi again,

    Please also check my reply on this thread.

    Guido

    Thread Starter Lobsterdm

    (@lobsterdm)

    Ok, i’ve added <?php date_i18n( the_field(‘event-start-date’) ); ?> but it’s not returning anything.

    This is an old installation so i’m just trying to get it to work how the client wants.

    Plugin Author Guido

    (@guido07111975)

    Hi,

    Your code contains the_field and that’s part of the Advanced Custom Fields (ACF) plugin. Is being used to output the value of a certain ACF field. Do you have this plugin installed?

    Guido

    Thread Starter Lobsterdm

    (@lobsterdm)

    Yes I do

    Plugin Author Guido

    (@guido07111975)

    This should work and output the start date in localized format as well:

    
    <?php $variable = get_field('event-start-date', $event->ID); ?> 
    <h4><?php echo date_i18n( get_option( 'date_format' ), $variable ); ?></h4>
    

    Guido

    ps. for this you don’t need ACF plugin, you could also use get_post_meta() to retrieve field value.

    Thread Starter Lobsterdm

    (@lobsterdm)

    You’re awesome thank you that works perfectly

    Plugin Author Guido

    (@guido07111975)

    Great, you’re welcome!

    Nice client website, by the way ??

    Guido

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Event display ignoring events with times’ is closed to new replies.