Is it possible to retrieve meta content for the get_next_post() and get_previous_post()?

I'm currently using the following method, but not having much luck:

<?php $prev_post = get_previous_post(); ?>
<?php $prev_post->post_title(); ?> /* Returns content */
<?php echo get_post_meta( $prev_post->ID, 'meta_box1', true); ?> /* Doesn't return content */

Should I be forming the call differently?

  • 1
    According to the codex get_previous_post() should return a WP_Object so IF you can verify that the function did return WP_Object and !empty() then to me, that looks like the correct way to get the post meta. Are you certain that the next post has the meta set? Are you certain the meta is being saved?
    – Howdy_McGee
    Commented Apr 28, 2014 at 16:47
  • 1
    You're right: your comment made me realized that I was doing a search for meta information in pages rather than posts! Thanks!
    – Marc P
    Commented Apr 28, 2014 at 17:29


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.