Created
August 24, 2011 17:54
-
-
Save jonathonbyrdziak/1168688 to your computer and use it in GitHub Desktop.
Wordpress get custom taxonomy function for loading all of the taxonomies and terms for a given post
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 | |
/** | |
* Function is responsible for building a taxonomy/term | |
* array for the given post type. This array will include | |
* all taxonomy objects associated with the post type. | |
* | |
* This function should be preloaded, normally by placing | |
* it into your functions.php file. | |
* | |
* @param string $post | |
* @return Array|Ambigous <multitype:, WP_Error> | |
*/ | |
function get_taxes_terms($post) | |
{ | |
//initializing | |
$taxes = get_object_taxonomies($post); | |
$args = array( | |
'orderby' => 'name', | |
'order' => 'ASC', | |
'fields' => 'all' | |
); | |
$taxTerms = array(); | |
if ($taxes) | |
{ | |
foreach ($taxes as $taxName) | |
{ | |
if (!isset($taxTerms[$taxName])) | |
{ | |
$taxTerms[$taxName] = array(); | |
} | |
$taxTerms[$taxName] = wp_get_object_terms( $post->ID, $taxName, $args ); | |
} | |
} | |
return $taxTerms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment