WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Flutter] Hiding Label When Key is Blank (2 posts)

  1. urbanroyal
    Member
    Posted 4 years ago #

    Fresh Page is great! But am having the most obnoxious issue. There is probably a simple solution and I'm just missing it.

    So when creating a post using Flutter, I often times only fill out about half of the fields I've created. But Flutter still creates custom fields for every field, simply leaving them blank. I'm using the following code to display the custom fields in my loop:

    <?php $customField = get_post_custom_values("name");
    if (isset($customField[0])) {
        echo "Name: ".$customField[0]."<br />";
    } ?>

    The problem is that since Flutter still creates the custom fields, but leaving them blank, I am still left with the label "Name:" on my post. How can I make the code conditional so if the custom field is blank, the label is not displayed?

  2. tidywebdev
    Member
    Posted 4 years ago #

    I've just started using Flutter, but I had a similar issues. I was using flutter's simplest get('variable') syntax. By default Flutter surrounds textbox fields with some HTML, so my empty fields were not really empty.

    You can fix this if you specify full arguments for the get() function like this:

    $myFlutterField = get('myFlutterField', 1, 1, false);

    The false argument at the end stops any html surrounding the value. So you can then use:

    if(!empty($myFlutterField))
    {
     //output value here
    }

    See the Flutter usage page for full info on the get() function.

    Hope this helps

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags