Enter your keyword

Blog

How to get previous and next post of given post id in Wordpress

function getPreviousNext($currenPostID){
    $postids = array();
    global $post;
    $post = get_post($currenPostID);
    $previous_post = get_previous_post();
    $next_post = get_next_post();
    $nextPost = get_post($next_post->ID);
    $prevPost = get_post($previous_post->ID);
    $postids["nextSlug"] = $prevPost->post_name;
    $postids["prevSlug"] = $nextPost->post_name;
    $postids["prevlink"] = $next_post->ID;
    $postids["nextlink"] = $previous_post->ID;
    return $postids;
}

No Comments

Add your review

Your email address will not be published.

* Feilds are Required.