• Resolved masare2

    (@masare2)


    I have created two new fields for each post ( “Customer” and “Customer2”) and I would like them to be shown at the top of the post if there is something inside, otherwise I would like them to be hidden.
    I’ve tried to modify the single.php file writing this:

    <div class="postmeta">
    	<span class="customer"> Customer: <?php echo get_post_meta( get_the_ID(), 'Customer', true); ?></span> <br />
    	<span class="customer2"> Secondary Customer: <?php echo get_post_meta( get_the_ID(), 'Customer2', true); ?></span>
    </div>

    this way both the fields are correctly shown, but how can I hide them if they are empty (I mean, sometimes I don’t have anything to write in “Customer” or in “Customer2”)
    could you help me ?
    I started recently to play with codes, so please be patient!!
    M2

Viewing 1 replies (of 1 total)
  • Thread Starter masare2

    (@masare2)

    I’ve solved this way, I hope it helps someone!

    <div class="postmeta">
    	<span class="customer"> Customer: <?php echo get_post_meta( get_the_ID(), 'customer', true); ?></span> <br />
    	<span class="committente2">
     <?php  $customer2 = get_post_meta( get_the_ID(), 'customer 2', true);
    if (!empty($customer2)){
    print (' Secondary Customer: ' );
    echo ($customer2);
    }  ; ?></span>
    </div>

Viewing 1 replies (of 1 total)
  • The topic ‘how not to show an empty field (single.php)’ is closed to new replies.