WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] Conditional statement (5 posts)

  1. ataxel
    Member
    Posted 2 years ago #

    I there, I really enjoy to get to know your plugin. I can now built more personal website and that is so great.

    As for now, i'm working on template and have some questions. For the moment, i'll only ask about not displaying an empty custom field. I mean if the custom field is empty, i won't print any label either.

    As for my small knowledge, it works with :


    <?php if($custom_field_name !== '') { ?>
    LABEL: <?php echo $custom_field_name; ?>
    <?php } ?

    Can you help me manage this part please.
    By the way, i read the 7 pages of topics here to find solution...

    Namaste, Lp(*

    http://wordpress.org/extend/plugins/custom-content-type-manager/

  2. 416BC
    Member
    Posted 2 years ago #

    This works for me.

    <?php
    $city = get_custom_field('location_city');
    
    if ($city !== ''): ?>
    	<strong>Location: City</strong> <?php echo $city; ?>
    <?php endif ?>
  3. 416BC
    Member
    Posted 2 years ago #

    Here is a bit shorter and cleaner.

    <?php
    if ((get_custom_field('location_city')) !== ''): ?>
         <strong>Location: City</strong> <?php print_custom_field('location_city'); ?><br />
    <?php endif ?>
  4. ataxel
    Member
    Posted 2 years ago #

    Thank you, it's really appreciate!

  5. 416BC
    Member
    Posted 2 years ago #

    Glad I could help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic