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

powered by WassUp

Recent Posts: Fully Net Worth . com

Gabby Morrison Height, Age, Net Worth, Wiki, Bio & More

Gabby Morrison Height, Age, Net Worth, Wiki, Bio & More

Gabby Morrison is a young American social media star who is best known for creating videos on the popular and trendy platform TikTok. In a short amount of time, Morrison has been able to garner over 2.1 million followers on the platform where she has received close to 70 million likes for her videos already. […]

Tony Lopez Height, Age, Bio, Net Worth, Wiki & More

Tony Lopez Height, Age, Bio, Net Worth, Wiki & More

Tony Lopez is an American Tik Tok star who is best known for his skills as a dancer and along with his older brother, Ondreaz Lopez completes the synergy of The Lopez Brothers. He has over 2.4 million followers on his profile on Tik Tok where he has received more than 40 million likes so […]

Cash Nasty Net Worth: How Much He Makes From YouTube?

Cash Nasty Net Worth: How Much He Makes From YouTube?

Cash Nasty is an American Youtuber who is known for running the Youtube channel called WhatChaMaCalling. Moreover, he is also on Twitch where he runs a channel called CashNastyGaming. As of 2019, Cash Nasty net worth is estimated to be $1.5 million. He was born on December 4, 1990  in Vidalia, Louisiana. Nasty has always been […]

%d bloggers like this: