Categories: Tips & Tricks

Calling custom fields for next/previous posts

With that said, I’d like to say I am using this snippet for a new theme I am building.

I want to pull a custom field from the “next” & “previous” post. So I used the following to do so:

<?php
  $previous_post = get_previous_post();
  $next_post = get_next_post();
  $image_prev = get_post_meta( $previous_post->ID, 'image', $single = true);
  $image_next = get_post_meta( $next_post->ID, 'image', $single = true);
?>

Simple. This is how I put it to use:

<?php if ( $image_prev != '' ) : ?>

  <img src="<?php echo FROSTY_SCRIPTS  ?>/thumb.php?src=<?php echo $image_prev; ?>&amp;h=50&amp;w=169&amp;zc=1&amp;q=80" alt="" />

<?php endif; ?>
Web Master

Hi, I am Miguel, I bought this site in 2009. So I now run or manage the site. Please visit my new website or follow me on twitter @W3i.

View Comments

Recent Posts

7 Finest Places on Web to Find Excellent WP themes

Photographers, avid bloggers, tech junkies, and even food bloggers have shown their love & trust…

33 minutes ago

WordPress VS Enterprise CMS – Which one to Pick?

WordPress has been one of the most dominating CMS and more domains are now going…

13 hours ago

Guidelines for Choosing the Best WordPress Theme for Your Website

Using a WordPress theme for a website comes with plenty of advantages. One great feature…

1 day ago

Top Six ways to Use QR Codes as a Web Design Tool

How can you link QR codes to digital content? When a QR code is read…

2 days ago

Should You Recycle Old Material to WordPress?

As a writer, or as a business owner doing some serious blogging, you probably wish…

2 days ago

The Complete In-Depth Guide to Getting Started with WordPress Development in 2022

Is WordPress Easy for Beginners? Yes, WordPress in all fairness is clean for novices to…

3 days ago