Support

Account

Home Forums General Issues Permalink call from Date Time Picker code

Unread

Permalink call from Date Time Picker code

  • I was reading this page

    https://www.advancedcustomfields.com/resources/date-time-picker/

    I used some code from there. It all works except I can’t get the permalink to work.

    I usually use the_permalink() but that doesn’t work. I tried echo get_permalink();

    $p->post_permalink

    Nothing works. Can you tell me what call should I use to get the link for the blog post?

    <?php

    // find date time now
    $date_now = date(‘Y-m-d H:i:s’);
    $time_now = strtotime($date_now);

    // find date time in 7 days
    $time_next_week = strtotime(‘+90 day’, $time_now);
    $date_next_week = date(‘Y-m-d H:i:s’, $time_next_week);

    // query events
    $posts = get_posts(array(
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘post’,
    ‘cat’ => ‘events’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘event_date’,
    ‘compare’ => ‘BETWEEN’,
    ‘value’ => array( $date_now, $date_next_week ),
    ‘type’ => ‘DATETIME’
    )
    ),
    ‘order’ => ‘ASC’,
    ‘orderby’ => ‘meta_value’,
    ‘meta_key’ => ‘event_date’,
    ‘meta_type’ => ‘DATETIME’
    ));

    if( $posts ): ?>

    <?php foreach( $posts as $p ): ?>
    <div class=”event”>
    <div class=”eventlocation”>
    <h3>“><?php echo $p->post_title; ?></h3>
    </div>
    <div class=”eventlocation”><?php the_field(‘event_location’, $p->ID); ?></div>
    <div class=”eventdate”> <?php the_field(‘event_date’, $p->ID); ?> | <?php the_field(‘event_time’, $p->ID); ?> – <?php the_field(‘event_end_time’, $p->ID); ?>
    </div>
    </div>
    <?php endforeach; ?>
    <?php endif; ?>

Viewing 1 post (of 1 total)

The topic ‘Permalink call from Date Time Picker code’ is closed to new replies.