Created
July 1, 2013 21:06
-
-
Save rosschapman/5904637 to your computer and use it in GitHub Desktop.
wp_get_category_names_for_any_post.php #wordpress
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 get_category_names_for_any_post(){ | |
// Create empty array for later | |
$categoriesArray = array(); | |
// Get current post type | |
$curentPostType = get_post_type($post->ID); | |
// Get taxonomy for current post | |
$curentPostTypeTaxonomyObject = get_object_taxonomies( $curentPostType ); | |
// Get taxonomy terms for current post | |
$currentPostTerms = wp_get_post_terms( $post->ID, $curentPostTypeTaxonomyObject); | |
// Loop through terms and create new array of term names | |
foreach ($currentPostTerms as $term ) { | |
$categoriesArray[] = $term->name; | |
} | |
return $categoriesArray; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment