Widget Logic
Conditional for a Post in a Certain Category within a Custom Taxonomy (2 posts)

  1. id eric
    Posted 4 years ago #

    I need to display a widget on a single post for all posts that are organized into a particular category for a custom taxonomy.

    For example, how would I display a widget on for all posts organized into the "Dogs" taxonomy category of the "Animals" taxonomy?

  2. id eric
    Posted 4 years ago #

    Alright, so apparently this need is not support with wordpress core functions. However, I found a great post on a related thread that provides the answer. ref

    Add this to your functions.php file:

    function is_city( $city ) {
        $cities = wp_get_object_terms( get_the_ID(), 'deals', array( 'fields' => 'names' )  );
        if( in_array( $city, $cities ) )
    	    return true;
        return false;

    Add this to your widget's "Widget logic" field:

    I have tested this, and it is working for me.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic