0

I have this snippet in my functions.php. I thought it worked, but I noticed that it shows events only from this year (I have more events that are next year) and also, I can't get the date format to work correctly. It shows the correct format, but the months are not in the locale of the website.

function custom_shortcode() {
    $today = date("Y/m/j");
    $args = array(
      'post_type'   => 'evenement',
      'order'       => 'ASC',
      'post_status' => 'publish',
      'meta_key'    => 'eventdate_begindate',
      'orderby'     => 'meta_value',
      'meta_query' => array(
        array(
           'key' => 'eventdate_begindate',
           'meta-value' => $value,
           'value' => $today,
           'compare' => '<=',
           'type' => 'CHAR'
       )
));

    $events = new WP_Query( $args );
    if( $events->have_posts() ) :
        $html = '<div class="owl-carousel owl-lazy">';
          while( $events->have_posts() ) :
            $events->the_post();
            $loc = get_post_meta(get_the_ID(), 'eloc_location', true);
            $bdate = get_post_meta(get_the_ID(), 'eventdate_begindate', true);
            $bdatef = DateTime::createFromFormat("Y-m-d", $bdate);
        $html .= '<div class="evsl-event" style="background-image:url(' . get_the_post_thumbnail_url($post->ID) . ')">';
        $html .= '<div class="evsl-event-content">';  
        $html .= '<h4>' . get_the_title() . '</h4>';
        $html .= '<span> ' . $bdatef->format('d F Y') . '</span><br>';
        $html .= '<span>' . $loc . '</span>';
        $html .= '</div>';
        $html .= '</div>';    
          endwhile;
          wp_reset_postdata();

        $html .= '</div>';

    else :
      esc_html_e( 'Er zijn geen evenementen', 'text-domain' );
    endif;

return $html;
}

Your Answer

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

Browse other questions tagged or ask your own question.