Skip to content

Instantly share code, notes, and snippets.

@jonathonbyrdziak
Created August 24, 2011 17:54
Show Gist options
  • Save jonathonbyrdziak/1168688 to your computer and use it in GitHub Desktop.
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
<?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