Issue
I am trying to show WordPress Category name in my Taxonomy page, but every time that Category has no post, its name won't be show. How can I show it, even when it's empty?
<?php
$term = get_queried_object();
$term->slug;
$terms = get_the_terms($post->ID, 'productcat');
$nameTerm = $terms[0]->name;
$linkTerm = get_term_link($terms[0]);
?>
<span><?php echo $nameTerm ?></span>
Solution
It sounds like you want to get all terms of the category, not just the post terms. Use get_terms
. You can pass hide_empty
to show the categories that don’t have posts.
<?php
$term = get_queried_object();
$term->slug;
$terms = get_terms( 'product_cat', array(
'hide_empty' => false,
) );
$nameTerm = $terms[0]->name;
$linkTerm = get_term_link($terms[0]);
?>
<span><?php echo $nameTerm ?></span>
Answered By - Noah Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.