WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] If Else for taxonomy (5 posts)

  1. oneofayykind
    Member
    Posted 3 years ago #

    I have created a taxonomy for my custom post type. The taxonomy is hierarchal and the name is featured and so is the slug. How can I write an if else so that if the taxonomy featured is checked off it shows x and if its not it shows y?

  2. iridiax
    Member
    Posted 3 years ago #

  3. oneofayykind
    Member
    Posted 3 years ago #

    Would it be possible to list an example? I'm trying to use <?php if() ?> to list posts that are using the featured taxonomy. I really am still learning so much of this so at this point I'm lost.

  4. MichaelH
    Member
    Posted 3 years ago #

    There is this:

    <?php
    // in post loop, if post has terms belonging to the taxonomy featured display a message
    $terms = wp_get_post_terms( $post->ID , 'featured', '');
    if ( !is_wp_error($terms) && $terms ) {
    echo 'found featured terms on this post';
    }
    ?>
  5. oneofayykind
    Member
    Posted 3 years ago #

    YES this worked thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags