Created
May 9, 2013 18:12
-
-
Save v9n/5549356 to your computer and use it in GitHub Desktop.
It's easy to get a list of taxonomy. wp_get_post_terms, get_term_list,..do the job. However, in the case you don't know the taxonomy name, then here is the code to find out it. This is take from WordPress core file. Meaning the function we need is: get_object_taxonomies
This file contains hidden or 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 get_post_taxonomies($post) { | |
// Passing an object | |
// Why another var?? $output = 'objects'; // name / objects | |
$taxonomies = get_object_taxonomies($post, 'objects'); | |
/*// Passing a string using get_post_type: return (string) post, page, custom... | |
$post_type = get_post_type($post); | |
$taxonomies = get_object_taxonomies($post_type, 'objects');*/ | |
/*// In the loop with the ID | |
$theID = get_the_ID(); | |
$post_type = get_post_type($theID); | |
$taxonomies = get_object_taxonomies($post_type, 'objects');*/ | |
// You can also use the global $post | |
// edited to fix previous error $tazonomies | |
// edited to force type hinting array | |
return (array) $taxonomies; // returning array of taxonomies | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment