Home Forums ACF PRO Next post and previous post links based on ACF date


Next post and previous post links based on ACF date

  • I am trying to create next and prev links based on an a date entered as an ACF. This is what I have so far. It works but it is still based on the date the past was created vs. the ACF date with the slug event_date:

    `if( get_adjacent_post(false, ”, true) ) {
    previous_post_link(‘%link’, ‘« Previous Post’);
    } else {
    $first = new WP_Query(‘posts_per_page=1&order=DESC&meta_key=event_date&orderby=meta_value’); $first->the_post();
    echo ‘<a href=”‘ . get_permalink() . ‘”>« Previous Post</a>’;
    }; ?>
    <span class=”pipe”>|</span> <a href=”/”>Home</a> <span class=”pipe”>|</span>
    if( get_adjacent_post(false, ”, false) ) {
    next_post_link(‘%link’, ‘Next Post »’);
    } else {
    $last = new WP_Query(‘posts_per_page=1&order=ASC&meta_key=event_date&orderby=meta_value’); $last->the_post();
    echo ‘<a href=”‘ . get_permalink() . ‘”>Next Post »</a>’;

Viewing 1 post (of 1 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.