Are you looking for a way to display the custom field value from previous and next posts? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display custom field value of previous and next post.
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
<?php $previous_post = get_previous_post(); $next_post = get_next_post(); $prev_value = get_post_meta( $previous_post->ID, 'CUSTOM_FIELD', $single = true); $next_value = get_post_meta( $next_post->ID, 'CUSTOM_FIELD', $single = true); ?> <?php if ( $prev_value != '' ) : ?> <p><?php echo $prev_value; ?></p> <p><?php echo $next_value; ?></p> <?php endif; ?>
Make sure to change the
CUSTOM_FIELD on line 4 and 5 to the name of the custom field you wish to display.
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.