WordPress.org

Support

Support » How-To and Troubleshooting » How to check if a displaying taxonomy have a defined custom post type

How to check if a displaying taxonomy have a defined custom post type

  • Hi.

    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.

Viewing 1 replies (of 1 total)
  • 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;
    			break;
    		}
    	}
    
    	return $is_tax;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘How to check if a displaying taxonomy have a defined custom post type’ is closed to new replies.
Skip to toolbar