Created
September 15, 2011 13:33
-
-
Save ocean90/1219233 to your computer and use it in GitHub Desktop.
WordPress: Check if taxonomy is assigned to a post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ds_is_taxonomy_assigned_to_post_type( 'schnipsel' ) ) | |
echo '<h3>Schnipsel Archiv</h3>'; | |
else | |
echo '<h3>Archiv</h3>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Prüft, ob eine gegebene oder aktuell nachgefragte Taxonomy einem gegebenen Post Type zugeordnet ist. | |
* | |
* @author Dominik Schilling | |
* @license GPLv2 | |
* @link http://wpgrafie.de/137/ | |
* | |
* @version 0.1 | |
* @param object|string $post_type | |
* @param string $taxonomy Optional. Standardwert ist null. | |
* @return bool True wenn Taxonomy dem Post Type zugeordnet ist, false wenn nicht und bei fehlerhafter Eingabe. | |
*/ | |
function ds_is_taxonomy_assigned_to_post_type( $post_type, $taxonomy = null ) { | |
if ( is_object( $post_type ) ) | |
$post_type = $post_type->post_type; | |
if ( empty( $post_type ) ) | |
return false; | |
$taxonomies = get_object_taxonomies( $post_type ); | |
if ( empty( $taxonomy ) ) | |
$taxonomy = get_query_var( 'taxonomy' ); | |
return in_array( $taxonomy, $taxonomies ); | |
} |
This is 11years old and it helped me today... Thanks for sharing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this - very usefull :)