Output the post taxonomy values in WordPress
-
First of all I should say that I’m a beginner, I want to apologize for all the mistakes and my ignorance in coding.
I’m trying to create a custom taxonomy and assign a value for each post, I’d like to output all the values of the taxonomy and mark the assigned one.
This is the code that I’ve tried to use:
if (has_term( 'A1', 'levels' )) { echo '<div class="level"><p class="level-title">level</p><p><mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> A2 B1 B2 C1 C2</p></div>'; }else{echo "";} if (has_term( 'A2', 'levels' )) { echo '<div class="level"><p class="level-title">level</p><p>A1 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> B1 B2 C1 C2</p></div>'; }else{echo "";} if (has_term( 'B1', 'levels' )) { echo '<div class="level"><p class="level-title">level</p><p>A1 A2 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> B2 C1 C2</p></div>'; }else{echo "";} if (has_term( 'B2', 'levels' )) { echo '<div class="level"><p class="level-title">level</p><p>A1 A2 B1 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> C1 C2</p></div>'; }else{echo "";} if (has_term( 'C1', 'levels' )) { echo '<div class="level"><p class="level-title">level</p><p>A1 A2 B1 B2 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> C2</p></div>'; }else{echo "";} if (has_term( 'C2', 'levels' )) { echo '<div class="level"><p class="level-title">level</p><p>A1 A2 B1 B2 C1 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark></p></div>'; }else{echo "";}
but it seems is not working appropriately, if I turn on the WP_DEBUG, it returns the following messages:
Notice: Undefined variable: post in /home/customer/www/englishwithfrancesca.com/public_html/wp-content/themes/storefront-child/storefront-template-functions.php on line 468
Notice: Trying to get property ‘ID’ of non-object in /home/customer/www/englishwithfrancesca.com/public_html/wp-content/themes/storefront-child/storefront-template-functions.php on line 468
I bet there’s a smarter way to code it.
Thanks in advance for any help!
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.