• Resolved jimario

    (@jimario)


    I am using WPUF and it is working fine. I have a form set up to create posts. In single.php, I use the following code to show data from the form in the post:

    <?php echo get_post_meta( $post->ID, 'sale_benchmark_pricing_per_sq_meter', true ); ?>

    Is there a way to get the labels for each form field to show IF there is form data returned? Currently I have my own labels within divs hard-coded in single.php as such:

    <div>Sale Benchmark Pricing:&nbsp;&nbsp;&nbsp;&nbsp;€<?php echo get_post_meta( $post->ID, 'sale_benchmark_pricing_per_sq_meter', true ); ?> /sqm </div>

    The problem is, if no data was entered into the form for this field, the hard-coded label still shows.

    • This topic was modified 6 years, 6 months ago by jimario.
    • This topic was modified 6 years, 6 months ago by jimario.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @jimario,

    Your code seems okay so far. Here is the sample snippet that you can use to check the empty value. Then output the data along with the label.

    <?php 
    $data = get_post_meta( $post->ID, 'sale_benchmark_pricing_per_sq_meter', true );
    
    if ( !empty( $data ) ) {?>
        <div>Sale Benchmark Pricing: <?php echo get_post_meta( $post->ID, 'sale_benchmark_pricing_per_sq_meter', true ); ?> /sqm </div>
    <?php } ?>
    
    Thread Starter jimario

    (@jimario)

    Thank you for the quick response. I will give this a shot.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to hide labels if no data returned’ is closed to new replies.