WordPress.org

Ready to get started?Download WordPress

Forums

if in taxonomy (2 posts)

  1. greencode
    Member
    Posted 1 year ago #

    Forgive me if this is obvious but I've only just started dabbling with custom post types and custom taxonomies. I'm struggling with this. When I was using category's I would use the code

    <?php
    if ( in_category( 'countryside' )) {
            echo 'Works';
    } else {
    	// Show nothing
    }
    ?>

    To check if a post was in the category "countryside" but how do I do the same with taxonomies?

    My Hierachal taxonomy is called "Collections" and within that I have the category of "Countryside" so I'm wanting to show something if the post is in "Countryside" but show something else if not.

    Any help would be greatly appreciated before I pull all of my hair out?!?!

  2. greencode
    Member
    Posted 1 year ago #

    Ah! Looks like I've found the answer:

    <?php
    if ( has_term( 'countryside','collection' )) {
            echo 'Works';
    } else {
    	echo 'Does not work!';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic