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

1 Comment

  1. eylültoprak

    July 7, 2009 at 5:13 pm

    Well, depending on how you can file attachments.
    .-= eylültoprak´s last blog ..al senin olsun… =-.

You must be logged in to post a comment Login

Random Search Terms

Title

Top Articles

Top Searches

powered by WassUp

Recent Posts: Fully Net Worth . com

DJ Drama Net Worth: How Rich is the American DJ Actually?

DJ Drama Net Worth: How Rich is the American DJ Actually?

Tyree Cinque Simmons, who is better known as DJ Drama, is an American DJ and record executive producer who is the co-founder of Generation Now that includes top artists such as Lil Uzi Vert and Jack Harlow. As of 2019, DJ Drama net worth is estimated to be around $12 million. Simmons was born on […]

600Breezy Net Worth: How Much is the Rapper Worth Actually?

600Breezy Net Worth: How Much is the Rapper Worth Actually?

Antonio Valentino King, who is better known by his stage name as 600 Breezy, is an American rapper and songwriter. He is also a member of the Black Disciples gang and has had some problems with the law in the past. As of 2019, 600Breezy net worth is estimated to be $700,000. He was born […]

Queen Key Net Worth: How Rich is the Rapper Actually?

Queen Key Net Worth: How Rich is the Rapper Actually?

Ke’Asha McClure, who is better known by her stage name as Queen Key is a rapper who made her breakthrough in 2016 with singles such as “Panic,” “Baked as a Pie,” and “Calling All Eaters.” She is known for her explicit songs and has recently released new projects called Eat My Pussy and Eat My […]

%d bloggers like this: