Plugin WP Types - display default value if empty (2 posts)

  1. Timmito
    Posted 3 years ago #

    Hey there,

    Just switched from magic fields to WP Types and to get things bulletproof I want to make sure if a field is empty, that there's still some content being displayed. In my case it's about defining an image...

    The code I've previously been using to achieve this is:

    <?php $values = get_post_custom_values("fieldname");
    if (isset($values[0])) {
    <img src="<?php echo get('fieldname'); ?>" alt="<?php the_title(); ?>"/>
    <?php }

    else { ?>
    <img src=""/>
    <?php } ?>

    Any idea how to achieve this with "types_render_field"? Can't get it to work with WP Types...

    Thanks in advance!

  2. wiktoratgmail
    Posted 3 years ago #

    This is working for me:

    $url=(types_render_field("url", array("raw"=>"true")));
    if ($url== '')
    { ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
    <?php } else { ?>
    <a href="<?php echo (types_render_field("url", array("raw"=>"true"))); ?>" target="_blank" rel="bookmark" title="<?php the_title(); ?>">
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic