Connect with us

Tips & Tricks

Calling custom fields for next/previous posts

Custom fields are definitely very useful and are used on many WordPress installs. Today I’m going to show you how to easily get custom fields values outside the loop.

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; ?>

Random Search Terms

Title

Top Articles

Top Searches

powered by WassUp

Recent Posts: Fully Net Worth . com

Luh Kel Net Worth: How Rich is the Rapper Actually?

Luh Kel Net Worth: How Rich is the Rapper Actually?

Turran Coleman, who is better known as Luh Kel, is an American singer and songwriter. He is best known for his hit single called “Wrong” which managed to peak at number 37 in the Billboard Hot R&B / Hip-Hop Songs chart and was certified Gold by RIAA in 2019. As of 2019, Luh Kel net […]

David Bellamy Net Worth: How Rich was the English Botanist?

David Bellamy Net Worth: How Rich was the English Botanist?

David Bellamy was an English author, broadcaster, botanist, and environmental campaigner. David Bellamy net worth at the time of his death is estimated to be $5 million. Bellamy was born on January 18, 1933, in London to parents Thomas Bellamy and Winifred May Bellamy. As a child, he wanted to become a ballet dancer, but […]

Ron Rivera Net Worth: How Rich is the former Panthers Coach?

Ron Rivera Net Worth: How Rich is the former Panthers Coach?

Ron Rivera is a retired football player and a former coach who managed Carolina Panthers in the National Football League. As of 2019, Ron Rivera net worth is estimated to be $5 million. Rivera was born on January 7, 1962, in Fort Ord, California. His father Eugenio Rivera was a military man. Due to his […]