Support

Account

Home Forums Front-end Issues display events will become …

Solved

display events will become …

  • hello,

    i want to make a loop to display events will becomme since today on my home page.

    i have post-type “concerts” sort by date picker. So i create this loop but it doesn’t work.

    Thanks you for your help,

    Ben

    <?php $date = get_field(“date-picker”);

    $dateTime = DateTime::createFromFormat(“Ymd”, $date);

    if ( is_object($dateTime) ) {
    $month = $dateTime->format(‘m’);
    $year = $dateTime->format(‘Y’);
    }

    ?>

    <?php query_posts(“posts_per_page=4&post_type=concerts&year=$year&monthnum=$month&meta_key=date-picker&orderby=meta_value_num&order=ASC” );?>

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”post-photo”>
    <div class=”thumbnail opacity”>“><?php the_post_thumbnail(‘thumbnail’); ?></div>
    <p><?php the_title();?></p><br/>
    <div class=”bouton-4″>“>voir l’album</div>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

  • or i used this but it doesn’t work

    <?

    $currentdate = date(“Y-m-d”,mktime(0,0,0,date(“m”),date(“d”)-1,date(“Y”)));

    query_posts( array(
    ‘meta_query’=> array(
    array(
    ‘key’ => ‘event_date’,
    ‘compare’ => ‘>’,
    ‘value’ => $currentdate,
    ‘type’ => ‘DATE’,
    )),
    ‘post_type’ => ‘concerts’,
    ‘meta_key’ => ‘event_date’,
    ‘orderby’ => ‘meta_value_num’,
    ‘posts_per_page’ => 4,
    ‘order’ => ‘ASC’,
    ‘paged’ => $paged ) );
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”post-photo”>
    <div class=”thumbnail opacity”>“><?php the_post_thumbnail(‘thumbnail’); ?></div>
    <p><?php the_title();?></p><br/>
    <div class=”bouton-4″>“>voir l’album</div>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>
    ?>

  • ok i found alone,
    i don’t put the good key name 😉

    it’s ok like this:

    $currentdate = date(“Y-m-d”,mktime(0,0,0,date(“m”),date(“d”)-1,date(“Y”)));

    query_posts( array(
    ‘meta_query’=> array(
    array(
    ‘key’ => ‘date-picker’,
    ‘compare’ => ‘>’,
    ‘value’ => $currentdate,
    ‘type’ => ‘DATE’,
    )),
    ‘post_type’ => ‘concerts’,
    ‘meta_key’ => ‘date-picker’,
    ‘orderby’ => ‘meta_value_num’,
    ‘posts_per_page’ => 4,
    ‘order’ => ‘ASC’,
    ) );
    ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”post-photo”>
    <div class=”thumbnail opacity”>”><?php the_post_thumbnail(‘thumbnail’); ?></div>
    <p><?php the_title();?></p><br/>
    <div class=”bouton-6″>voir l’album</div>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.