jcadima
12/17/2017 - 5:39 PM

Get Categories from Taxonomies


<?php
// this will go in singlg-recipesindex.php  custom post type for single posts under 
// recipesindex  custom post type
global $post;
echo '<pre>' ;
print_r($post) ;
echo '</pre>';

$category = get_the_category( $post->ID );
echo '<h2>POST ID: ' . $post->ID . '</h2>' ;

//get first category ( post->ID ,  'taxonomy_name')
$terms = get_the_terms( $post->ID , 'recipes' );
echo 'Taxonomy Category: ' .  $terms[0]->name ;

echo '<pre>' ;
print_r($terms) ;
echo '</pre>';


// Get all terms(categories) in this taxonomy
foreach ( $terms as $term ) {
	echo $term->name;
}