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.

1 Answer 1

    $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?


Your Answer

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

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