How to check if a displaying taxonomy have a defined custom post type (2 posts)

  1. TheMadcore
    Posted 3 years ago #


    First of all, sorry for my english. Isn´t my native language.

    I´m in the need to check if a displaying taxonomy has a defined custom post type associated. I´m using is_post_type_archive('post type') and is_taxonomy('tax'), but in the project I´m working on have a lot of custom taxonomies associated to different post types, and creating the conditionals for all the taxonomies in the different templates is a hell.

    I searched the codex for something, but found nothing. The idea is to built a function in the form of is_tax_has_type('post type') or something alike. I´m not telling you to make me the function, beacuse that´s not funny and I´m no gonna learn anything that way. Only need a clue or clues to start making myself the function, that´s all.

    Thanks in advance for your time and help.

  2. tamarazuk
    Posted 3 years ago #

    Maybe this is a little late, but I was looking for a similar thing and wrote some code to deal with it. It might not be perfect but it works.

    function is_post_type_tax( $post_type ) {
    	$taxonomies = get_object_taxonomies( $type );
    	$is_tax = false;
    	foreach ( $taxonomies as $tax ) {
    		if ( is_tax( $tax ) ) {
    			$is_tax = true;
    	return $is_tax;

Topic Closed

This topic has been closed to new replies.

About this Topic