Support » Fixing WordPress » Only display custom field if present and add content filters

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Try it with this [untested]:

    <?php
    $credits = get_post_meta($post->ID, 'credits', true);
    if ($credits != ''  ) : ?>
            <aside class="credits">
              <?php echo apply_filters('the_content', $credits); ?>
            </aside>
            <?php endif; ?>

    Ignore the above, I got myself in a pickle. The code below works ok.

    <?php if( $credits = get_post_meta($post->ID, 'credits', true) ): ?>
            <aside class="credits">
              <?php echo apply_filters('the_content', $credits); ?>
            </aside>
    <?php endif; ?>

    Thanks Keesiemeijer, it seems your code works as well.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Only display custom field if present and add content filters’ is closed to new replies.