Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save v9n/5549356 to your computer and use it in GitHub Desktop.
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
<?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