I am a noobie. Building my new theme. I just need to get 3 separate data:

  • $image = direct link to the next post thumb image (just the link)
  • $name = Next post name
  • $url = Next post URL

Looked at previous / next post with thumbnail dosnt work for me....

Thank you for any help)

1 Answer 1


You can use get_adjacent_post function for retrieving that data. This function retrieve adjacent post. Can either be next or previous post.

For previous post


  $prevpost = get_adjacent_post( false, '', true, 'category' );

  $image = get_the_post_thumbnail( $prevpost );
  $name = get_the_title( $prevpost );
  $url = get_permalink( $prevpost );


For next post


  $nextpost = get_adjacent_post( false, '', false, 'category' );

  $image = get_the_post_thumbnail( $nextpost );
  $name = get_the_title( $nextpost );
  $url = get_permalink( $nextpost );

  • I would cache it in a variable $next_post = ..., otherwise it's a little expensive to call it repeatedly. Commented Jun 14, 2015 at 10:14
  • 1
    Originally I did but when I tested it didn't work with the variable. So had to change it. But that could be me only :) Anyway changed it again.
    – Robert hue
    Commented Jun 14, 2015 at 10:44
  • 1
    Also wrap $nextpost/$prevpost in an if - if there is no next/previous post, the following get_* functions will return data for the current post. Commented Jun 14, 2015 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.