WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say you have a few custom fields (I use the advanced custom fields plugin for it). There is an extra field in posts called 'afbeelding_onder'.

It is not required but on index.php within the loop the custom field 'afbeelding onder' from the last post will be printed. If it is possible, is there a way to check if the custom field is empty, if it isn't than it will print the value, but else (when the custom field is empty) the value of the last post which contains a value in that box will be printed.

Hope my question was clear enough, my English grammar is not that good.

share|improve this question
up vote 1 down vote accepted
    $prev_post = get_previous_post();
    echo '<p>' . get_field('afbeelding_onder', $prev_post->ID) . '</p>';
    echo '<p>' . get_field('afbeelding_onder') . '</p>';

not tested. you might want to include a while loop, if the previous post does also not have that value set?

share|improve this answer
Thanks, this is a nice code to study :) – Maartje Nov 28 '13 at 12:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.