Support » Fixing WordPress » Plugin WP Types – display default value if empty

  • 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!

Viewing 1 replies (of 1 total)
  • 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 } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Plugin WP Types – display default value if empty’ is closed to new replies.