• Resolved dorich

    (@dorich)


    I want to create a condition whereby if a post is attached to a particular taxonomy then some additional code is executed on a modified single.php but I can’t find a way to directly check for the taxonomy.
    I thought “is_tax” might do the job but it seems that this tag is only effective for archive pages, which I assume means a page that is generated from a template using the taxonomy name.

    Is there a direct way to read the taxonomy from a single post so that I can do something similar to:
    if (is_tax('chapter')) {additional code}

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter dorich

    (@dorich)

    I worked out one solution for this as follows:

    $terms = get_the_terms( $post->ID , 'chapter');
     if($terms) { *additional code to be added to the template* }

    If any terms in the taxonomy ‘chapter’ are returned the additional code is added to the template otherwise the additional code is omitted.

    I don’t know if this needs any additional error checking but the code as shown works by including code on the appropriate posts and omitting it where its not required.

    Any suggestions on improvements would be welcome.

Viewing 1 replies (of 1 total)
  • The topic ‘Is there a way to check if a single post is attached to a particular taxonomy’ is closed to new replies.