WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Taxonomy Conditional - Output code only if taxonomy has a value (4 posts)

  1. ruhelamin
    Member
    Posted 1 year ago #

    Hi, im using Custom Taxonomies in my theme, for example:

    <?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ', '' ); ?>

    Is it possible to do a conditional statement to output some code only if that taxonomy has a value/term entered in it in the admin posts page.

    For example:

    IF taxonomy has a value then output this:

    <dt>Gender: </dt>
          <dd><?php echo get_the_term_list( $post->ID, 'gender', '', ' / ', '' ); ?><span></span></dd>

    ELSE (if it has no values) then output NOTHING!

    Is this possible? Thanks in advance.

  2. Andrew Bartel
    Member
    Posted 1 year ago #

    <?php 
    
    $baz = get_the_term_list( $post->ID, 'people', 'People: ', ', ', '' ); 
    
    if($baz) {
    ?>
    <dt>Gender: </dt>
          <dd><?php echo $baz ?><span></span></dd>
    <?php
    }
    ?>
  3. ruhelamin
    Member
    Posted 1 year ago #

    Excellent Andrew, thank you very much.

  4. Andrew Bartel
    Member
    Posted 1 year ago #

    Sure thing, happy coding.

Topic Closed

This topic has been closed to new replies.

About this Topic