Tagged: categories, Portfolio
Hi,
On the site I am working on each Portfolio item can be in multiple categories so I would like to list the categories on the single-portfolio page. I read a bunch of posts and followed the code in the one that came the closest, but still no luck, I’m getting an empty array.
I added the following code in my child theme to loop-portfolio-single.php. To test it, I have echoed the post id and category array to the screen. The post id is correct, but the category array is empty.I have tried both portfolio-entries and portfolio-categories as the taxonomy. I would appreciate any advice you could give me.
echo $post_id; // test
$terms = get_the_terms($post_id, 'portfolio-entries');
print_r ($terms); // test
if ( $terms && ! is_wp_error( $terms ) ) {
echo "sparky"; // test
$terms_mediums = array();
foreach ( $terms as $term ) {
$newterms[$term->slug] = $term;
}
ksort($newterms);
foreach ( $newterms as $term ) {
$terms_mediums[] = $term->name;
}
$terms_list = join( ", ", $terms_mediums );
echo $terms_list;
unset($newterms);
}
else { echo "nosparky"; // test }
echo '</div>';
Result:
571WP_Error Object ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy ) ) [error_data] => Array ( ) ) nosparky
Hey kallym!
Thank you for using Enfold.
It should be “portfolio_entries”, not “portfolio-entries”.
Cheers!
Ismael
That worked! Thank you!!.